LNCD

Table of Contents

Table of Contents

  • Git
    • Track Changes
      • Commit messages
    • See Changes
    • Advanced
  • LNCD Home
  • Administration
  • Notebooks
  • Journal Club Presentations
  • Publications
  • Current Projects
  • Completed Projects
  • Current Grants
  • Datasets by Project
  • Brain ROIs and Measures
  • ️Tools And Methods
  • Big Data
  • RA Homepage
  • Recent Changes
  • Maintenance
  • Site Map
  • Random Page
LNCD
Docs » Git

Git

git is a “distributed version control system” (dVCS) or “source control management” (SCM) tool used to track changes, primarily for source code in text files. git has command line and graphical interfaces.

Alternative SCM tools include fossil, hg, pijul. For version controlling (large binary/non-text neuroimaging) data, see datalad or dvc

git is not github. Github is a Microsoft-owned source forge adding a social network, identity services, and other features not included in the git system (issue tracking, patch/fork management). Other forges include gitlab, sr.ht, codeberg.

See Github setup for integrating local repos with github remote.

For more see

  • https://happygitwithr.com/
  • http://neuroimaging-data-science.org/content/002-datasci-toolbox/002-git.html
  • https://git-scm.com/doc

Track Changes

On the command line in terminal/with shell, using git follows the add,commit,push pattern. Need a mnemonic? Think of the Adorable Computer Penguins on the MobaXterm screensaver.

git add $file   # move changes in $file to "staging"
git commit      # annotate staged files, commit to history
git push        # send changes to a server (e.g. github)

Don't give file paths to commit or push.

Only the git add (or friends like git mv and git rm) command takes file paths as arguments.

git commit and push work on the cumulative adds to create a single snapshot, not individual files.

By default, git commit will open Vim to use to write the commit message.

  1. Push i to put vim in insert mode.
  2. write your message.
  3. push Esc to go back to command mode
  4. :wq to write and quit.

Commit messages

Each commit in git includes a human-annotated short description in prose. While it's tempting and easy use `“update”` as the entire commit message, future you and colleges will appreciate a more detailed history. There are competing specifications to help guide better commit messages:

  • https://www.conventionalcommits.org/
  • https://gitmoji.dev/specification

Examples

Two commit messages in conventional commits vs gitmoji

feat: age model with GAM instead of LM
fix: outlier detection applied to all EEG columns
✨️ model.py: age GAM instead of LM
🐛 plot.R: apply outlier detection ∀ EEG cols

See Changes

A huge benefit of version control is to see the what's changed. This can be done with web, graphical, and command line interfaces.

The command line/terminal commands for viewing what's changed include

git log         # history of all changes
git status      # what's been git add-ed/git rm-ed, modified, and untracked
git diff        # what's changed in tracked files
git blame $file # show what commit/author is responsible for each line

If the output is more than a screenful, these commands will launched put the output in the pager less.

  • arrow keys navigate
  • push / to start a search
  • push q to quit

Advanced

  • working trees for working on more than one branch at a time
  • git add $file; git commit –amend –noedit; git push –force
  • rebase, esp with emacs+magit's rebase UI
  • confusing terms
  • popular git config options
Previous Next