I'm working on a project that is quickly becoming so large I feel the need to back it up. Although I trust Github with all of my work, I'd hate to not have a backup incase something goes wrong. For this reason, I use Bitbucket as a backup.

Bitbucket is nice because they offer free, private git hosting.

Amazon CodeCommit is another great choice but I haven't tested it yet.

After you create your account and repo, below are the commands I use to save to different git repositories.


Getting Started

I'm assuming that you already have a repo both on Github and your local computer and all you're trying to do is back up your existing repo on Bitbucket.

I'm also assuming that you want want to learn how to do this using terminal. If you'd prefer to use a web interface, I suggest reading this article on Bitbucket.

Setting Your Remote URL

Here's how to change the remote url using set-url.

git remote set-url origin https://domain.com/your/remote/url

How to Add Your Second Repo Host

If at any point, you want to add yet another backup, then here is how to do it.

First check the status of your current remote repositories.

git remote -v

The next step is to add the URL of the git repo. URL's come in one of two paths: ssh or https.

git remote add set-url alias_name_of_repository https://domain.com/your/remote/url

Alt: If you only want to change the --push path

git remote add set-url alias_name_of_repository --push https://domain.com/your/remote/url

Double check your work.

git remote -v

Source


Pushing Data to Your Second Host

git push -u alias_name_of_repository master

Source


Pushing Data to Your Primary Host

git push origin master

Pulling From Multiple Hosts

If you want to fetch the master branch from

git remote update

Pulling From a Single Host

Fetch the Master Branch from Your Second Host and Pull it into your current Head.

git pull alias_name_of_repository master

Deleting a Second Host

This will --delete a remote URL that was set to --push to a remote repo.

git remote set-url alias_name_of_repository --push --delete https://domain.com/your/remote/url

More