Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote git branches not shown with `git branch -r`?

Tags:

git

I have two directories on my local machine pointing to the same remote git repository. When I issue the command git branch -r in one of the directories I get a longer list of remote branches then in the other directory. How is that possible ?
It seems that some of the remote branches are 'hidden' in one directory and are visible in the other.

like image 365
nadav Avatar asked Aug 22 '10 09:08

nadav


People also ask

Does git branch show remote branches?

To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .

How do I get branches from remote repository?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.


3 Answers

I had the same issue, couldn't get the remote branches on one of my local directories. git branch -r would show less branches and also not the top-most change, while on the other directory everything was refreshing nicely.

To fix this, I did git config -l on both directories and found out that I was missing the remote.origin.fetch setting. Running the following line fixed my problem:

git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git fetch 

From github.com:username/test2
   2bd5e5e..2619d39  master     -> origin/master
 * [new branch]      remotebr2  -> origin/remotebr2
 * [new branch]      remotebranch -> origin/remotebranch
like image 151
ksymeon Avatar answered Oct 16 '22 11:10

ksymeon


I think you should fetch and prune:

prune 
Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>". 

With --dry-run option, report what branches will be pruned, but do not actually prune them.

With this commandlines:

git fetch
git remote prune origin
like image 21
Andreas Rehm Avatar answered Oct 16 '22 10:10

Andreas Rehm


Are both repositories up-to-date? Try running git fetch and see if that fixes it.

like image 2
mkarasek Avatar answered Oct 16 '22 11:10

mkarasek