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
.)
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.
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 .
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.
The refs are probably "packed" in .git/packed-refs
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With