git pull --help
Incorporates changes from a remote repository into the current branch.
I pull the git repository for offline vi开发者_StackOverflowew of the code and like to have the updated code for the different branches. How do I pull the code for all the branches easily without doing a pull for each branch manually?
--all -- Fetch all remotes.
--all didn't help.
If the local repository is used for read only and none of the files are modified, then the below script will do the trick.
for i in $(git branch | sed 's/^.//'); do git checkout $i; git pull; done
There seems to be no git equivalent command for the same.
Like Praveen Sripati's answer, but as a shell function and it brings you back to the branch you started on.
Just put this in your ~/.bash_aliases file:
function pull-all () {
START=$(git branch | grep '\*' | set 's/^.//');
for i in $(git branch | sed 's/^.//'); do
git checkout $i;
git pull || break;
done;
git checkout $START;
};
With the || break it does a satisfactory job not screwing things up if there's a conflict or the like.
pull
merges remote branches into your current local branch, so pulling all remote branches is probably not what you want.
Inspired by @cellofellow I added this to my .profile
on Mac OS X:
function git-pull-all() {
START=$(git symbolic-ref --short -q HEAD);
for branch in $(git branch | sed 's/^.//'); do
git checkout $branch;
git pull ${1:-origin} $branch || break;
done;
git checkout $START;
};
function git-push-all() {
git push --all ${1:-origin};
};
The main differences are:
I am getting the current branch with
git branch | grep '\*' | set 's/^.//'
instead ofgit branch | grep '\*' | set 's/^.//'
.You can supply a remote as a parameter e.g.
git-pull-all origin
. If you omit the parameter, it defaults to origin.Also added a similar shortcut to push multiple branches back the server.
If you only need the offline functionality, you can simple call git fetch -all
to get all current information. Now you have all information at your disk and can work offline. Simple merge or checkout the branch you want to work on. Git pull is git fetch && git merge
.
You have to merge each branch individually. If you merged in multiple branches and more than one of them had merge conflicts, how could you possibly resolve then at the same time?
精彩评论