Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Git store remote tracking branches

Tags:

git

I have to Git repos repo1 and repo2. There are three branches master, alpha and beta in repo1. repo2 clones from repo1.

In repo2, I can see remote tracking branches with git branch -a:

remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/alpha
remotes/origin/beta

But the folder .git/refs/remotes/origin/ in repo2 only has a single file HEAD, whose content is:

ref: refs/remotes/origin/master

So this HEAD is a symbolic ref. But why does it point to a ref that doesn't exist? BTW, where does repo2 store the information of alpha and beta? (repo2 knows alpha and beta because it displays them in git branch -a.)

like image 821
Cyker Avatar asked Nov 02 '12 22:11

Cyker


People also ask

How does git keep track of branches?

Git stores all references under the . git/refs folder and branches are stored in the directory . git/refs/heads. Since branch is a simple text file we can just create a file with the contents of a commit hash.

How do I find my github 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.


1 Answers

The refs are probably "packed" in .git/packed-refs.

like image 141
CB Bailey Avatar answered Nov 15 '22 23:11

CB Bailey