Skip to main content

Cloning a repo

The Aims​

The objective for this exercise is to learn how to clone a repo, and keep the local and remote repos in sync.

Steps​

  1. If you do not already have a personal GitHub account, create one now. You must use a PERSONAL email address - do not use a firm email address. For more guidance see the separate info sheet on creating a Github account.

  2. Log onto Github

  3. Create a new repo in Github – go to the Repositories tab and click on the New button.

  4. Give the repository a name, such as GitLab2. Keep the repository as public. Tick the box to add a Readme file, then click on the Create Repository button.

Step 4 Screenshot

  1. Click on the green Code button, then in the drop down click on the copy button to copy the URL of the repo to your clipboard.

Step 5 Screenshot

  1. In the git bash shell, navigate to the C:\Course folder, then run the command git clone <<url>>

Step 6 Screenshot

  1. View the folder that has been created in Windows explorer – note that there should be a file present (README.md) and a sub folder called .git

  2. Using notepad, Edit the file called README.md – enter any content you like into this file and save it.

  3. Run the command git status to see what the current status of your workspace is – make sure you navigate into the project folder first.

Step 9 Screenshot

Note that the file you edited is in your workspace but is not yet in the staging area.

  1. Run the command git add . to add the file into the staging area.

  2. Run the command git status to see what the current status of your project is.

Step 11 Screenshot

Note that the file you added now appears in green. The updated file is in both your workspace and the staging area, and is the same file in both places.

  1. Commit the file to your local repo with git commit -m "update to readme"

Step 12 Screenshot

  1. Run the command git status to see what the current status of your project is.

Step 13 Screenshot

  1. Run the command git push to synchronize the local changes with the remote repo

Step 14 Screenshot

  1. Open the file on the Github website – check that the local changes appear there.

  2. Edit the file on the Github website – there is a pencil icon at the top right of the file. When you have made some changes click on the green “Commit changes” button. When you click on this you’ll get a popup where you can enter a commit message. Just click on the green “Commit Changes” button again to save the change. Note that you wouldn’t normally edit a file on Github – we are doing this so that we can see how to pull remote changes that are not present in our local repo.

  3. Run git pull to update the local repo with the remote changes.

Step 17 Screenshot

Open the file in Notepad and check that the changes you made on the server are present locally.

  1. Run the command git log to see a list of the commits that were made both on the local and remote repos.