Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching all remote branches into a bare Git repository

Tags:

git

github

I set up a Github post-receive hook, which runs a script on my web server whenever a push is made to my Github repository.

When the script runs, I want it to keep a local bare clone of the repository synchronized with my Github repository. To do this, I have it run this command:

git fetch origin && git reset --soft refs/remotes/origin/master

Then, if from my workstation I push to master on Github, everything works just fine. However, if I push to another remote branch, the changes are not reflected in my server's local bare repository.

I'm assuming there's some way to have the script fetch all of the remote branches, but I don't know how to do this. I know newer versions of git have a --all option for fetch/pull, but I'm using git version 1.6.3.3, which doesn't seem to have this option.

Does anyone know how I can get my script to fetch all remote branches?

Thanks!

like image 364
Tom Avatar asked Oct 05 '10 17:10

Tom


People also ask

How do I fetch all 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 .

Does git fetch pull all branches?

Thanks for the lead! git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .

How do I clone a repository with all branches?

The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.


2 Answers

git fetch origin '*:*' worked for me.

like image 151
temoto Avatar answered Oct 28 '22 11:10

temoto


Use a shell script perhaps?

#!/bin/sh

for i in `git remote show`; do
    git fetch $i;
done;

Note: Small terminology error in your question: The --all option of git fetch|pull fetches all "remotes", not "remote branches".

like image 21
artagnon Avatar answered Oct 28 '22 13:10

artagnon