What is Git?

  • Source code management (SCM) tool
  • Developed by Linus Torvalds for the Linux kernel
  • Keep track of source code in commits and branches
    • Commit = “unit of code change”

Why should I use git?

  • Backup your code
  • Synchronize between laptop and HPC
  • Know what you did 2 months ago


  • Git is an industry standard
  • Collaborate with others
  • Share your code

A git repository…

…is just a folder with a special .git directory.


Create a repository by typing

git init

within a directory.

The four git states

The four git states

Display modified files and their states:

git status
git diff

Add a modified file to the staging area:

git add <FILE>

Commit all staged files:

git commit

Browse history

git log

Working with branches

List branches

git branch -v

Create a new branch from current commit

git branch <NAME>

Switch to another branch

git switch <NAME>

Ignoring files

Create a file named .gitignore in the git repository.

Example:

.Rhistory
.RData

*.nb.html
plots/*.pdf

Configuring git

Configuration file at ~/.gitconfig. Modify with text-editor or with git config command.

When collaborating online, it is important to set your identity – it will be associated with every commit:

git config --global user.name "Your name"
git config --global user.email "mail@example.com"

Links