This short guide will show you how to clone your git repository on Github onto your Linux Machine. Setting up version control in your development environment is a crucial step to successful software development.
1. To access our remote GitHub repository locally, we will be cloning it from github with an ssh url. In order to clone the repository over ssh, we need to set up a set of ssh keys on our Linux Machine. Github provides useful documentation on generating an ssh key and adding it to your ssh-agent. Once your keys are created you can print the contents of your public key to your screen and copy them:
2. Once you have your public key copied to your clipboard, you can add them to your GitHub account’s list of known ssh keys. This will authorize our machine to access our remote repository on GitHub. You can follow Github’s documentation once again.
3. Next you’ll want to install git. If you are using a Debian version of linux with the aptitude package manager, you can install and setup git with:
sudo apt-get install git
git config --global user.name "Pericror User"
git config --global user.email "email@example.com"
The user name and email will be used to identify and commits you make from this machine.
4. To clone our remote repository we need to retrieve its ssh-url. Get the ssh-url of the repository you want by visiting the project page and clicking the Clone or Download button. Then click the little blue Use SSH text from the pop up and click the clipboard icon.
5. Now we are ready to clone the remote project onto our Linux machine. In the directory where we want our project to be cloned we can type:
git clone <ssh-url>
<ssh-url> is the ssh-url copied in step 4.
6. We have now set up a git repository on our development machine, and can use it to track changes.
To see which files we have changed locally, in the repo directory use:
We can can push our local changes back into the remote branch after making changes with:
git add .
git commit -m "Example commit message"
Or pull the latest changes from the remote with:
If we want to discard our local changes and override them with the remote:
git fetch --all
git reset --hard origin/master