Git: Not a valid object name?

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
From github.com:sleepycat/myapp
* [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.

Advertisements

4 thoughts on “Git: Not a valid object name?”

  1. there are small diff between git pull and git fetch.

    “You can do a git fetch at any time to update your local copy of a remote branch.”

    “A git pull is what you would do to bring your repository up to date with a remote repository.”

    To pull data from remote, you must have local object. That what git fetch done for you. :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s