Working With Branches in Git Cheat Sheet
Working With Branches in Git Cheat Sheet
presented by
TOWER — the best Git client for Mac and Windows
Keep in mind that you can only create new branches in your Publishing Branches
local repository (you will see them remotely when published). While you can’t create new branches on remote repositories,
you can most definitely publish an existing local branch by
By default, the new branch will be based on your currently typing this command:
checked out revision. If you’d like to start at a specific revision,
simply add that revision’s hash at the end of the command,
$ git push -u origin <local-branch>
like so:
$ git switch <other-branch> The most common example is having a local branch track a
remote one, so that you can simply type “git push” or “git pull”
OR
without additional parameters to keep everything in sync. This
can be quickly achieved by typing the command below:
$ git checkout <other-branch>
$ git branch --track <new-branch> origin/<base-branch>
Renaming Branches You can also use the “git checkout” command to achieve this.
This command assumes you’ve already checked out the If you want to name the local branch after the remote one, you
branch you’d like to rename (your local HEAD branch): only have to specify the remote branch’s name:
$ git log <origin/main>..<main> To delete a remote branch, keep in mind that the command
is totally different:
Rebasing Branches
Rebasing is an alternative to merging - both achieve the
same goal, but the Rebase option re-writes the project history,
creating a straight line. As a result, you get a linear history,
which may be preferred by some teams.