2

A peer created a new branch.

I ran

git pull

git branch - I did not see his new branch.

So then I...

git checkout newBranch

git branch - Now I see his new branch

Why did git branch only update after I ran checkout instead of after pull?

4 Answers 4

4

Because as far as I understand it git branch only lists your local branches. Your repository still has the remote branch there, hence why you can checkout the branch. And once you checkout that branch you've create your local version of said branch.

Hence why git branch now shows the branch after you checked it out.

git branch -a - Lists all branches, both local and remote-tracking branches git branch or git branch --list - Lists all existing local branches git branch -r - Lists remote-tracking branches 
Sign up to request clarification or add additional context in comments.

Comments

2

If you want to see all branches on the remote repo you can use

git branch -a 

I normally use this with grep to find the branch I want.

git branch -a |grep <what I want> 

If you just create a branch with the same name as your peer's branch it won't work you have to base it off of the remote branch

Your peer has to push to the central repo with something like

git push --set-upstream origin <branch name> 

To base your branch off of the remote branch you can use

git checkout -b <branch_name> origin/<branch name> 

2 Comments

I did get a copy of his branch locally by using git checkout newBranch. I checked git log and I see his changes.
git branch lists local branches. It is available but it is still a remote branch if you haven't created a local branch to track it. By doing git checkout newBranch I think git assumed you wanted to track the equivalent branch on the remote repo and hence you created your local branch and now git branch lists it.
0
git branch 

shows local branches

to list remote branches :

git branch -a 

to get all the remote branches :

git fetch 

then you can

git checkout newBranch 

4 Comments

Once you fetch is newBranch still considered a remote branch?
after fetching its now in your local repo.
Ok, so I'm back to my original question. I ran git pull and that is similar to running git fetch. Since the branch is now a local branch why does it not show when I run git branch?
I think you meant git checkout origin/newBranch but this would still leave him in a detached head state.
0

In your case git checkout doesn't really check out the remote branch newName, instead it creates a shiny new local branch newName which is set up to track the remote branch.

Thus by checking out "newBranch" you also created an equally named local branch "newBranch" which is then naturally shown by git branch

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.