Skip to content
UoL CS Notes

Version Control with git

COMP122 Labs

A full textbook on git as available called: ProGit.

Local Setup

The bare minimum of setup is to set the user.name and user.email:

$ git config --global user.name "Ben Weston"
$ git config --global user.email sgbweso@liverpool.ac.uk

Creating a Repository

To initialise a new repository you can do the following inside a new folder:

$ git init

To check the status of the repo use:

$ git status

Adding Files

To stage a new file that you have made, run the following:

$ git add newFile.txt

To commit this file to the database you can use the following:

$ git commit -m "Adding the newest file ever."

To use a text editor to draft the commit message, ommit the -m flag.

You can see your history of coimmits by using:

$ git log

Changing and Reverting Files

To add the changes for all modified (but not new) files:

$ git commit -a -m "Adding changes."

To remove to the previous commit of a file:

$ git checkout file.txt

To pick a particular commit view the commit history and run the following:

$ git log
$ git checkout <commit identifier> file.txt

You can also just use the identifier prefix.