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 key
message. Enter the desired path or just pressEnter
to 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)’
ssh-add ~/.ssh/id_rsa
- 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 key
button. - Give a descriptive name for your key in the
Title
field, paste the key from the clipboard (ctrl+v
orcmd+v
) into theKey
field and click theAdd SSH key
button.
Now you’ve got Git connected to your GitHub account and it’s time to add your project to a GitHub repository.