If you installed Xcode from the you should skip this task, otherwise run:
brewinstallgit
When done, to test that it installed properly you can run:
git--version
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):
gitconfig--globaluser.name"Your Name Here"gitconfig--globaluser.email"your_email@youremail.com"
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.
gitconfig--globalcredential.helperosxkeychain
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-agentis 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:
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.
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
ssh-keygen -t rsa
# Generating public/private rsa key pair.
# Enter file in which to save the key
(/Users/tony/.ssh/id_rsa): /Users/tony/.ssh/daton89_github
ls ~/.ssh
config id_rsa id_rsa.pub daton89_github daton89_github.pub
The authenticity of host 'github.com (IP ADDRESS)' can't be established.RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.Are you sure you want to continue connecting (yes/no)?
Hi daton89! You've successfully authenticated, but GitHub does not
provide shell access.