简体   繁体   中英

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)

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM