Quick one today guys…
I need to setup a local branch to track the latest on a remote branch on github. An easy way to do that is:
git checkout -b snowden --track origin/snowden
Basically, it says we are going to switch to branch “snowden” after we create it with the “-b” command. Then we are going to have that branch track the remote version we have on “origin”. So in this case track the remote “snowden” branch.
That’s it, super simple.
On a side note, if you find that you are unable to merge these branches to master and have unexpected results. You need to use a merge strategy that exactly copies the branch to master, instead of a downstream version. To do that:
git checkout snowden git merge -s ours master git checkout master git merge snowden
fatal: ‘origin/snowden’ is not a commit and a branch ‘snowden’ cannot be created from it
fatal: ‘origin/snowden’ is not a commit and a branch ‘snowden’ cannot be created from it
I get the same error and I’d love to know why this isn’t working.
git checkout -b mybranch –track origin/mybranch
…does raise this error message: “origin/mybranch is not a commit…”, while the following works just fine:
git checkout -b mybranch
git push -u origin/mybranch
…why?
Your command can be even more concise:
git checkout -t origin/snowden
Using -t without -b implies creation of a branch using the same name as the remote.
Documentation: https://git-scm.com/docs/git-checkout#git-checkout-emgitcheckoutem-b-Bltnewbranchgtltstartpointgt