Git
Installation
If you installed Xcode from the you should skip this task, otherwise run:
When done, to test that it installed properly you can run:
And which git
should output /usr/local/bin/git
.
Next, we'll define your Git user (should be the same name and email you use for GitHub):
They will get added to your .gitconfig
file.
To push code to your GitHub repositories, we're going to use the recommended HTTPS method (versus SSH). To prevent git
from asking for your username and password every time you push a commit you can cache your credentials by running the following command, as described in the instructions.
Adding an SSH key in your GitHub account
We suggest to use an SSH Key for each account.
Check for existing SSH keys
First, we need to check for existing SSH keys on your computer. We do this by running:
Check the directory listing to see if you have files named either id_rsa.pub
or id_dsa.pub
. If you already have this you need to use a different name for your new SSH Key.
Generate a new SSH key
To create a key with a name or path other than the default, specify the full path to the key. For example, to create a key called my-new-ssh-key
, enter a path like the one shown at the prompt: (/Users/tony/.ssh/id_rsa): /Users/tony/.ssh/daton89_github
Change the default location and name and press enter.
Enter and re-enter a passphrase when prompted. The command creates your identity with its public and private keys.
Now list the contents of ~/.ssh
to view the key files.
Add your SSH key to the ssh-agent
Run the following commands to make sure that the ssh-agent
is running.
No matter what operating system version you run you need to run this command to complete this step:
To make sure that your key was added to the agent you can run:
Copy and add the public key to your GitHub account
The last step is to let GitHub know about your SSH key. Run this command to copy your key to your clipboard:
Then go to GitHub and input your new SSH key. Paste your key in the "Key" text box and pick a name that represents the computer you're currently using.
Return to your terminal window and run the following command:
You may see a warning like this:
Verify that the fingerprint in the message you see matches, then type yes
:
Verify that the resulting message contains your username. If you receive a "permission denied" message, see "Error: Permission denied (publickey)".
More Resources
Adding an SSH Key in your BitBucket account
You can generate and add your Key to ssh-agent with the same process used for GitHub. For add your public key to your account you need to follow these steps:
From Bitbucket, choose Bitbucket settings from your avatar in the lower left. The Account settings page opens.
Click SSH Keys.
In your terminal copy the public key with this command:
pbcopy < ~/.ssh/<your pub key name>.pub
From BitBucket, click Add key.
Enter a Label for the Key.
Paste the copied public key into the SSH Key field.
Click Save.
Return to your terminal window and verify your configuration and username by entering the following command:
ssh -T git@bitbucket.org
The command message tells you which of your Bitbucket accounts can log in with that key.
If you get an error message with
Permission denied (publickey)
, check the Troubleshoot SSH issues page for help.
Now that you've got an SSH key set up, use the SSH URL the next time you clone a repository. If you already have a repository that you cloned over HTTPS, change the remote URL for your repository to use its SSH URL.
More Resources
Last updated