How to push to multiple remotes in git

Categories:

Solution

Add pushurl to remote branches in .git/config:

.git/config
[branch "master"]  
	remote = github
	merge = refs/heads/master
[remote "github"]
	fetch = +refs/heads/*:refs/remotes/github/*
	url = git@github.com:$user/$project.git
	pushurl = git@github.com:$user/$project.git
	pushurl = git@gitlab.com:$user/$project.git
	pushurl = git@bitbucket.org:$user/$project.git
[remote "gitlab"]
	fetch = +refs/heads/*:refs/remotes/gitlab/*
	url = git@gitlab.com:$user/$project.git
	pushurl = git@github.com:$user/$project.git
	pushurl = git@gitlab.com:$user/$project.git
	pushurl = git@bitbucket.org:$user/$project.git
[remote "bitbucket"]
	fetch = +refs/heads/*:refs/remotes/bitbucket/*
	url = git@bitbucket.org:$user/$project.git
	pushurl = git@github.com:$user/$project.git
	pushurl = git@gitlab.com:$user/$project.git
	pushurl = git@bitbucket.org:$user/$project.git

Change $user and $project accordinly.

See Also