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!
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 .
Thanks for the lead! git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .
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.
git fetch origin '*:*'
worked for me.
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".
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