George Cooper
George Cooper

Reputation: 73

How to setup git config for pushing to two different remote repositories from the same local repository?

I have been working on a project for the past few weeks using a repository on bitbucket. Recently, I decided that I also want the repository on my github account. I have successfully set it up so that every time I push, I push to both repositories. The github repo essentially serves as an exact copy of my commits to the bitbucket repo. My problem is that I have to enter my name and username for both accounts every time I push.

I have researched the new conditional includes for using different accounts, but it seems like that only works when the repositories have different file paths, which in this case they don't.

Does anyone know of a way to setup my .git/config file so it automatically uses a specific name/email combo depending on which repository it is pushing to?

Upvotes: 1

Views: 540

Answers (2)

Night Train
Night Train

Reputation: 2576

your question has already been answered here: Git: Pushing to two repos in one command
So basically you have to add your additional repository with

git remote set-url --add --push origin [email protected]:TEST/REPO.git

(or you can use https instead of ssh). Now you're ready to go to push to both repos via

git push origin

if you are using Bitbucket or Gitlab they also offer you to mirror the repository (depending on your Account type). In Bitbucket there are also plenty of Plugins that can mirror a GitHub repo.

Upvotes: 0

RakhuNathan
RakhuNathan

Reputation: 83

You can add 2 origins to your project like below

git remote add origin origin_url.git
git remote add origin2 origin_url.git

After making changes each time to your code base, use git commit -m "commit message"

Then push to both repos,

git push origin master
git push origin2 master

This pushes to both of your repositories each time.

Upvotes: 2

Related Questions