Notes
Cloning a GitHub repository pulls a copy of the files found on the website along with all versions of the projects. This allows users to push their own changes to the remote repository or pull changes that others have made. If you have not setup a local repository with Git, see this topic: Setting up a Local Repository in GitHub using Git.
For our purposes, this can be useful if you want to push changes to the remote repository from your personal device and then pull those changes onto a lab computer. This can allow students to always have access to their up-to-date files regardless of which computer they use.
1. Cloning a Repository
-
Visit https://github.com/ and navigate to the page of the repository you wish to clone.
-
Click on the green “Code” drop-down menu on the top right and copy the URL of the repository. Make sure the URL is in the HTTPS format.
-
Open Git Bash and change the directory to the location where you want the repository to be cloned.
-
Lastly, use the following command and replace the URL with the one you copied previously. Please note, you will be asked to login to your GitHub account from the terminal.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
2. Pull Changes from Remote Repository
-
The Pull command is used to fetch and merge changes from the remote repository to the local repository.
-
Open Git Bash and ensure the directory is set to the location of the folder where your local repository is saved.
-
Use the command shown below and remember to replace the URL with the one you copied from the chosen remote repository on GitHub. Now the changes in the GitHub repository should be identical to those found in your local repository.
git pull https://github.com/YOUR-USERNAME/YOUR-REPOSITORY