I have been using branches in my general development workflow for while but a lot of my development has just been local. Recently I have been moving between computers and pushing my project up to github. This works well but introduces a minor twist on branching; creating local tracking branches for remote branches.
I have been using git branch –track and life has been good. Well today I must have done something different:
mike@sleepycat:~/projects/my_app$ git branch –track haml_val origin/haml_val
fatal: Not a valid object name: ‘origin/haml_val’.
A fatality huh? I checked my syntax and it really was fine. Curious I checked my remotes:
mike@sleepycat:~/projects/myapp$ git remote show origin
haml_val new (next fetch will store in remotes/origin)
From that I decide that a quick git pull (which I believe runs git fetch and then get merge) should do the trick but I get the same error. After some head scratching it turns out that the solution really is fetch:
mike@sleepycat:~/projects/myapp$ git fetch origin
* [new branch] haml_val -> origin/haml_val
bf4ba85..83f687f master -> origin/master
mike@sleepycat:~/projects/myapp$ git branch –track haml_val origin/haml_val
Branch haml_val set up to track remote branch haml_val from origin.
Success! I still don’t know why that would work and git pull wouldn’t but either way its a lesson learned.