Working with Git

Where to host your git

Although you can host a git repository on your PC, it is typical to host it on a server with a browser-based interface. Popular websites for hosting git repositories are:

The University of Melbourne also has instances of GitLab running on its servers so that you can rest assured that you data is local and safe:

Clone your git

Once you have created a git repository on a server and initialized it, you can clone the repository to your local machine using

git clone <url>

where <url> is replaced with the URL of you repository, for example:

git clone https://gitlab.unimelb.edu.au/asclinic/asclinic-system.git

If you have setup your account on the server to work with ssh keys from your PC (see these GitLab instructions for example) then the <url> uses the format git@, for example:

git@gitlab.unimelb.edu.au:asclinic/asclinic-system.git

Typical git workflow

  • Add, edit, delete files on your PC using your favourite text editor and file manager (i.e., cp, vi, rm)

  • git status to display the files you have changed.

  • git diff to display the content of the files you have changed, highlighting only the changes you made, i.e., the diff erences.

  • git pull to fetch and integrate changes from the server and provide you with an initial indication of potential merge conflicts.

    • Note: git pull does not delete any of the changes your made, it only integrates changes from the server if they cause no conflects.

  • git add . to add all changes you made to the staging index.

    • Note: to add individual files, use git add <file_path_and_name>

  • git status to display the files are staged and ready to be committed.

  • git commit -m "<Write a descriptive commit message here>" to commit the stage files locally.

    • Note: be sure to write a descriptive commit message as you do not know what future reason will cause you to be looking back through your commits.

    • Note: committed changes are only local to your PC.

  • git status to double check that the commit was successful.

  • git push to upload your commits to the repository on the server.

View previous commits

  • git log to display the version history of the current branch.

  • git log --stat to display also some statistics about the version history.

  • git log --help to display the manual entry for git log

  • git diff <commit1> <commit2> to display the differences between <commit1> and :code`<commit2>`, which are the hash keys displayed by git log

  • git diff --help to display the manual entry for git diff