Using git

git is a version control system. It is important to remember throughout this document that it is intended to keep a history of changes and a full history of versions of your code, or other files. The fact that using git provides backups at each stage should always be considered a convenient side effect.

Avoiding Commands: Git the easy way

Without commands, some of the more advanced features of Git are not available, however most are still usable.

The Git client we suggest is GitHub Desktop.

Downloading a git repository

If you have a repository online which you wish to download with git and use, you can execute the clone command:

$ git clone git@gitlab.com:meridiangrp/brand.git brand

It is worth spending a moment to break this command down:

  • The git clone part runs the git program and tells it that you wish to clone a repository.
  • The git@gitlab.com:meridiangrp/brand.git part is a URI which specifies where the repository is located. It can either be an SSH type location, which will usually start git@someweb.site, or an HTTPS type, which starts with https://. SSH type is preferred, but requires an SSH key to be set up with both the machine accessing the repository and the git server.
  • The brand part specifies where to clone the repository to. It must be either an empty or non-existant folder. . can be used to clone to the current directory.

This will download the repository ready for use.

Making a new repository

To make a new repository go into a folder with which you wish to start using git and run the command:

$ git init

Then add the remote (the git server) with the command:

$ git remote add origin git@gitlab.com:meridiangrp/brand.git

The URI to use should be given to you by your git host.

Syncronising changes with the remote

You might not always be the only person making changes to your repository. To see if any changes have been made, run:

$ git fetch

If running this shows nothing, no changes have been made. Otherwise, it should suggest how many changes. If you wish to actually then download the changes to your copy of the repository, run:

$ git pull

If you have made changes to the repository that need to be uploaded to the remote, run:

$ git push

Note that if this is your first push, you may need to explicitly set the master branch on the 'origin' remote:

$ git push -u origin master

Making changes

When making changes to files in a git repository, they start off unstaged. These will not be uploaded. When you have completed adding a feature to your repository, ie. something with making a version for, you can add the files you have changed, or remove them if you have deleted them:

$ git add file/path
$ git rm file/path

Once you have staged all the changes with the above commands, you can commit your changes to the repository. Note that at this stage they are still saved locally on your computer:

$ git commit

You will be prompted to add a message explaining what your commit contains. You can then push.

How often should I make commits?

Do make commits for:

  • A new feature that is complete and working
  • A new asset or collection of assets
  • A change or improvement to code

Do not make commits for:

  • An incomplete feature
  • An untested portion of code
  • A collection of files which are completely unrelated

Moving on to more complex situations

Git is a powerful tool, and this only covers the very basics. It is worth spending some time to learn what git can do. It might be worth finding out about:

  • Branching and Merging
  • Amending commits
  • Resolving merge conflicts
  • Rolling back changes that have broken something
  • Tags
  • man git