18

I'm stil learning git and not sure how some basic things work. I created a local branch by doing:

git branch AppStore

I can't remember exactly how I pushed this branch to github.com, but I can see MyBranch on the repository. When I do

git branch -a

I see this:

  ARC
* AppStore
  Refactoring
  Release3
  master
  remotes/origin/AppStore
  remotes/origin/HEAD -> origin/master

There are more remotes listed as well. So from my computer where I created the branch, I see the AppStore branch. However, none of my coworkers can. When we tried a

git pull origin AppStore

It grabbed the changes. But when we tried

git checkout AppStore 
or
git checkout origin AppStore

We were not able to. What are we missing? Thanks!

Edit:

I did try this according to VonC's answer:

git push --set-upstream origin AppStore

After putting in my credentials, I get:

Branch AppStore set up to track remote branch AppStore from origin.
Everything up-to-date

But my coworkers still cannot see the branch :-.

Crystal
  • 28,460
  • 62
  • 219
  • 393
  • Are you sure you are all referring to the same thing when you say "origin"? You can have a look with `git remote -v` – Chronial Oct 04 '12 at 15:55
  • A very similar problem - [Git: Cannot see new remote branch](https://stackoverflow.com/q/12730344/465053). – RBT Apr 04 '18 at 06:19

2 Answers2

30

You need to publish your branch on your upstream repo, while tracking it locally (making sure your local branch keep in synch with that new remote branch: see "What is a tracking branch")

git push --set-upstream origin AppStore

As mentioned in the comments, the other developers need to fetch what has been pushed (included the new branch).
A git fetch origin is one way, but if you are unsure of the name of the remote repo, a git remote update works just fine.

That will update their remote branches, but won't create a local branch of the same name, as detailed in "Track all remote git branches as local branches".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So I thought I did that before, and I ran that command again. My coworkers still cannot see my branch. I edited my post for the details. – Crystal Oct 04 '12 at 15:45
  • 1
    @Crystal After they `git fetch`, they still need to checkout that remote branch as a local branch in their own local repo: see http://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches/6300386#6300386: it is an answer to http://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches which illustrates that you don't see by default new remote branches. – VonC Oct 04 '12 at 15:50
  • 1
    So after the git remote update was used, I could then see the remote AppStore branch. I don't remember having to call update before, but at least it works now! Thx! – Crystal Oct 04 '12 at 16:21
  • So after I push a branch, do they always need to git fetch. – Crystal Oct 04 '12 at 16:24
  • @Crystal: yes: `git fetch` is mandatory for other local repos to fetch from a "blessed" remote repo. I have edited the answer to include that step. – VonC Oct 04 '12 at 16:40
  • 1
    `git remote update` refreshed `git branch -r` such that I can now see my coworker's branch. – Matt Bearson Nov 03 '15 at 23:27
  • `git remote update` was all my coworker needed to do and it worked just fine for updating the list of existing branches. Thanks! – shieldgenerator7 May 13 '16 at 17:44
14

When you do a git branch xyz it creates a branch xyz on your local machine. Generally you create a new branch off the master branch so that it has the master's code. After creating the branch xyz, you make changes and then you have to git push origin xyz for the branch to be visible on github.

Doing git branch -a will show your branches in your machine. Till you push your branch you cannot find it on the remote repo.

noMAD
  • 7,744
  • 19
  • 56
  • 94