I have git repo living on Amazon CodeCommit but I want to save backups on Github or Bitbucket. Here's how:
Step 0 - Change Directory
First change directories to the git repo on your local drive.
Step 1 - Add Bitbucket as a remote backup
You can create a remote git url by adding
remote. In this example, I created a repo on bitbucket with an alias "mybitbucket".
git remote add mybitbucket firstname.lastname@example.org:chrisjmendez/repo.git
Step 2 - Add Github as a second remote backup
git remote add set-url mygithub email@example.com:chrisjmendez/repo.git
Step 3 - Business as usual
Now that you've added two remote backups, you can continue business as usual.
git add -A
git commit -m 'my commit message'
Step 4 - Push to a specific repo
If you want to specifically push to your github repo.
git push -u mygithub
Step 5 - To origin an all remote backups
Push to all repos.
git push -u --all
If you get a
Permission Denied error, check your access on your local machine and on Github.
firstname.lastname@example.org: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights
It's helpful to first review what ssh keys are stored on your local machine. Open
Terminal and type
ls -al ~/.ssh to see what combination of public (
.pub) and private keys are available.
ls -al ~/.ssh
Terminal to open
~/.ssh/config and confirm that you have some configuration that looks like this.
Host github.com IdentityFile ~/.ssh/id_rsa # Default Example # IdentityFile ~/.ssh/my_custom_key IdentitiesOnly yes
If you do not, then follow these instructions on how to create an SSH key.
Assuming you've created an SSH key for your local machine, confirm that the public key (
.pub) is stored in Github > Settings > Keys.
Finally, double-check and make sure your username is associated to the repo.