Session 1: Alice starts with a private repository

Why is Alice using a version control system:

  • It is easy to manage a few files. But for 100 files and more, she needs tool support.
  • She finds web up- and download clumsy. If the file is on the web, then it is not there where she needs it for work: on her local file system
  • For files used in collaboration, she wants to know who made the change, when, and for what purpose.

Why is Alice using Git:

  • Git development was initiated by Linus Torvalds, the developer of the Linux kernel. That indicates quality.
  • For about two years (or more) Open Source Software (OSS) developers seem to prefer Git and GitHub.
  • She works for the ESA wonderland. The ESA Thematic Exploitation Platform (TEP) Reference Architecture and Standards recommend Git (see OSS Best Practices).
  • She has a friend who has partners and clients who did not choose a common standard. He had to learn them all: ClearCase, CVS, Subversion, Git, etc.
  • She knows EODC. They push collaboration and pull standards from GitLab.

Alice configures her Git client: config --global|--list

Set user's global options (on Linux):

git config --global user.name "Alice from Wonderland"
git config --global user.email alice@wonderland.net
git config --global color.ui true
git config --global core.safecrlf warn
git config --global core.autocrlf input

On Windows, set core.autocrlf to true.

Check user's global options with: git config --global --list

Alice turns a directory into a Git repository: init, add, commit

It's just init, add and commit, but to get standardization of line endings (LF), and to exclude generated files, she does a little bit more:

cd <dir>               # for example `cci_sm_demo_src`
git init
git status
git add .gitattributes
git add .gitignore
git add .
git status
git commit
git checkout HEAD -- . # remove CRLF from working directory, if any
git status
git log

Here is a procedure for automatically fixing all line endings after changing core.autocrlf option or .gitattributes file:

git status           # check status
git add . -u         # Save current files, so that no work is lost
git commit -m "Save files before refreshing line endings."
git rm --cached -r . # remove every file from index (cache, staging area)
git reset --hard     # rewrite index to pick up all new line endings
git add .            # add changed files back
git commit -m "Normalize all line endings."

Alice edits files: status, diff, add, commit, log

vi <file>

git status
git diff
git add <file>
git diff --cached
git status
git commit
git status

git log
git log --oneline
git log --name-status
git log -p

Move and remove files or directories: mv, rm

git mv <old_path> <new_path>
git rm <path>

Commit options: -m, -a, --amend

git commit -m "<message>"
git commit -a             # skip `git add` and commit all changes
git commit --amend        # DO before pushing, DON'T after pushing

Alice knows how to discard undesired changes: reset, checkout, revert

Fix cache (aka index, staging area), then working directory:

git reset HEAD <file>   # resets index, keeps changes in working directory
git checkout -- <file>  # discards changes from working directory

Restore working directory after things got messed up entirely:

git reset --hard HEAD
git reset --hard <commit> # DO before pushing, DON'T after pushing

Compensate a bad commit (can be done any time):

git revert <commit>