epsilones
epsilones

Reputation: 11629

Tracking a git branch issue

I have cloned a repo using git. Another user created a new branch, call it foo (there are so two branches master and foo). I created another branch foo to track remote foo. So I ran this command : git branch --set-upstream foo origin/foo. But I have an error message telling me : fatal: Not a valid object name: 'origin/foo' Can anybody help ? When I run git remote origin show I have the message :

* remote origin
  Fetch URL: ssh://***
  Push  URL: ssh://***
  HEAD branch: foo
  Remote branches:
    master   tracked
    foo new (next fetch will store in remotes/origin)
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

Upvotes: 0

Views: 196

Answers (1)

Simon Boudrias
Simon Boudrias

Reputation: 44649

you must first fetch or pull the branch up to your local repo.

git fetch origin
# OR
git pull origin

After that, you can checkout foo

git checkout foo

And, you could use the above command you wrote to track origin/foo with another local branch name (put in your call, just checkout as you use the same name anyway).

Git remote are only somewhere you can pull/push change. But in reality, all what git do is on your local drive, so you cannot interact with remote branch unless you fetch them first to your locale. origin/foo is only a label on a sha-1 commit id that you hold locally. When you use origin/foo, you reference the local label, not the remote status (there's no ssh connection made while referencing a remote branch).

Upvotes: 2

Related Questions