nerc-ceh.github.io

https://nerc-ceh.github.io/version_control/exercise1

Exercise 1. Create your first Git repository

This exercise will take you through your first steps of applying version control using Git to a folder and its contents. You will cover:

Prerequisite: SourceTree installed

There are many clients for Git, in these exercises you will use SourceTree to manage Git. SourceTree is a Git client for Windows and Mac. If you haven’t yet installed it please do so using these instructions: https://nerc-ceh.github.io/version_control/install_sourcetree_windows

Note about command line

SourceTree gives you a graphical interface to manage Git and our exercises use that interface. However, Git can be used from the command line, and this may ultimately be your preferred option. For your reference we have included this script https://nerc-ceh.github.io/version_control/commandline_exercise1.txt, which shows you how to do exercise 1 entirely from the command line. You can enter commands in SourceTree if you go to: Actions > Open in Terminal.

However, for the classroom exercises, please use Source Tree as shown below rather than attempting the command line, since this keeps it easier for the trainers.

Step 1. Create your working project

This step creates a project folder with sub-folders and files ready for the rest of the exercise.

Step 2. Enable Git on your new project

This step adds the Git repository to the root of your project folder.

Step 3. Populate your new repository

Your new Git repository does not yet contain any files to version control, that is all files are currently Untracked. This is why they have a question mark next to them in SourceTree. This step puts all your files into Git, which is a two step process of Staging and then Committing them.

Step 4. Edit files and commit changes to Git

In this step you will edit some files and commit your changes to Git.

Step 5. Stage specific files

In this step you will edit two files, but Stage and Commit them separately to illustrate how commits can be used to organise your edits.

Step 6. Review the Git log and checkout a version

You should now have a range of file changes committed to Git. In this step you will look at the log of your edits and checkout one of those revisions.

s

Step 7. Tagging

As you can imagine, the Git log soon fills with many commits. There are times when you will want to identify a specific point in the log as something more significant - such as when you have completed major blocks of work, reached a milestone or finished a major change to modelling or website code. This is a release point that you can then refer to via a version number - eg v1.0.1 of my model or website. In Git this is called an annotated tag. The complete state of your repository is stored against this tag. This step will add an annotated tag to your repository.

Step 8. Ignoring files

It is very useful to be able to exclude some files from version control, for example you may have other processes that generate temporary files in your project. Ignoring files is done by adding a file named .gitignore to the root folder of your project. File names and file patterns added to it are ignored by Git. SourceTree makes this easy to do as follows.

You will be given several options, that allow you to ignore multiple files or just this one. Select Ignore exact filename(s) to only ignore this file and press OK.

End of exercise 1