* Last Updated: 2013-08-26
* Fixed: Bug in the gitpullall() script. – 2013-07-23
* Refactored: gitpullall() – 2013-08-26
* Updated: gitpullall() – 2015-03-07: Now it can handle branches. So pulling on branch works. The old version always pulled from master. This version uses the name of current branch then get the same one from the remote.
(e.g. remote: github, local branch: some-fix <=pull= github/some-fix) * Added: gitpullall() for Z shell (zsh) - 2015-03-07

Both Github and Bitbucket are good SCM hosting services. For some reason, you probably want to migrate your project from Github to Bitbucket or vice versa. It’s easy because you just need to change the remote repository info. Sometimes, you want to keep your code in both places which means you want to push it to both Github and Bitbucket.

Pushing to both Github and Bitbucket is easy.

Here is a project cloned from Github. If you check out the remote repository info, it has only Github repo info.

The YOUR_PROJECT/.git/config file, of course, has only Github info.

To add a remote git repository on Bitbucket, use git remote set-url.

Now, it has Bitbucket info too.


It’s enough for pushing to both Github and Bitbucket. So once it’s done, you can just do

Whenever you want to push to both.

If it doesn’t work, try git push -u origin master to set upstream.

Next time, you can just do

Make some changes, Commit and Push

If what you need is only to push to Github and Bitbucket then you don’t need to read this post any further. However, if you also want to pull data from both Github and Bitbucket, it requires a little more extra steps.

Before I show the steps, I need to point out another case that you might want to know. With what I’ve done here, it fetches the data only from Github when running the git pull command. If what you want is only changing it to make it pull from Bitbucket, it’s simple. You just need to swap the positions of origin urls in the YOUR_PROJECT/.git/config file.

So change from this


Now it pulls from Bitbucket instead of Github.

To pull from both Github and Bitbucket, first add the remote repository information using git remote.

You can add both Github and Bitbucket or just the one that is not pulled when running git pull. It’s all up to you.
Now, the YOUR_PROJECT/.git/config file contains the information of the new remote repositories just added.

YOUR_PROJECT/.git/config now has “github” and “bitbucket” as well as “origin”.

If you run git pull, it still pulls from only Github so you need to also run git pull bitbucket master.

* pull from Github


* pull from Bitbucket

If you want to pull it from all the remote repositories, you can use a function in shell script.

Add the following function to .bash_aliases or .bashrc or .profile depending on your OS (sorry Windows users).

~/.bash_aliases or ~/.bashrc or ~/.profile

* gitpullall() for Z shell (zsh) (Add the following function to ~/.zshrc)

Then you can simply run gitpullall to pull from all the remote repositories specified in the YOUR_PROJECT/.git/config file.

To ignore repositories when pulling, add the remote repository names to the repos_to_ignore variable in the gitpullall function above.

Pull other branch than master from the remote.

* License for gitpullall (Opensource)