- Create a new branch:
git branch <branch-name>
- Create a new branch from a specific commit:
git branch <branch-name> <commit-hash | branch-name>
- Create a new branch and switch to it:
git checkout -b <new-branch-name>
- Switch to an existing branch:
git checkout <branch-name>
- Commit changes on the current branch:
git commit -m "message"
- Merge another branch into the current branch:
git merge <branch-name>
- Abort a merge:
git merge --abort
- Rebase the current branch onto another branch:
git rebase <branch-name>
- Abort a rebase:
git rebase --abort
- Cherry-pick a commit from another branch:
git cherry-pick <commit-hash>
- Revert a commit on the current branch:
git revert <commit-hash>
- Push a new local branch to remote "origin":
git push -u origin <branch-name>
- Push changes to a remote branch:
git push origin <branch-name>
- Fetch all branches from remote "origin":
git fetch origin
- Fetch specific branche from remote "origin":
git fetch origin <branch-name>
- Pull changes from a remote branch:
git pull origin <branch-name>
- Delete a local branch:
git branch -d <branch-name>
(safe delete)
- Force delete a local branch:
git branch -D <branch-name>
- Delete a remote branch:
git push origin --delete <branch-name>