How to connect Git to a GitHub account
If you need to collaborate on your project with other developers or you want to share it with someone, this is a great time to connect your local repository to the remote one. The most popular solutions to storing remote repositories are GitHub, GitLab and Bitbucket. In this article, I’ll show how to connect local git to the GitHub account.
Follow the steps to connect Git to your GitHub account:
- Open a terminal and configure your username for your local Git:
git config --global user.name 'YOUR_NAME'
- Set Git email with the command below:
git config --global user.email 'YOUR@EMAIL'
- Generate a new SSH key with the command:
ssh-keygen -t rsa -b 4096 -C ‘YOUR@EMAIL’
- The terminal will prompt
Enter a file in which to save the keymessage. Enter the desired path or just press
Enterto save the default file location (recommended).
- Enter a secure passphrase. You must remember it! The passphrase is used to ensure an extra level of security in case if someone gains access to your computer.
- Add the newly-created key to ssh-agent:
eval ‘$(ssh-agent -s)’
- Add the SSH key to your GitHub account:
xclip -sel clip < ~/.ssh/id_rsa.pub.
- On the Github, go to Settings > SSH and GPG keys and click the
New SSH keybutton.
- Give a descriptive name for your key in the
Titlefield, paste the key from the clipboard (
cmd+v) into the
Keyfield and click the
Add SSH keybutton.
Now you’ve got Git connected to your GitHub account and it’s time to add your project to a GitHub repository.