From Christoph's Personal Wiki
Jump to: navigation, search

Git is a distributed revision control / software configuration management project created by Linus Torvalds, initially for the Linux kernel development.

Git is by far my favourite revision control system. I not only use it for software management, I also use it as my backup system for any of my text files.



  • Quick help:
$ git help      # returns most common commands
$ git help -a   # get a list of all installed git commands
$ man git-add   # man page on the 'add' command
  • Start a new git repository:
$ mkdir my_new_project && cd my_new_project
$ git init
# create some new files, then:
$ git add .
$ git commit
$ git commit -am 'initial commit message'
  • See what has changed since last commit:
$ git diff
  • A more concise way to view what has changed and what needs to be done:
$ git status
  • Clone a specific remote branch:
$ git clone --single-branch --branch <branchname> <remote-repo>


  • View current git user:
$ git config
  • Change to a different git user:
$ git config --global ""
  • Check git log for a specific function in a specific (e.g., Python) file:
# Syntax:
$ git log -L :<funcname>:<file>

# Example:
$ git log -L
commit b5ac4b65f9554a32fbec64435171c07a20a52de8
Author: Christoph Champ <>
Date:   Sat Jun 15 18:47:12 2019 -0700
    initial commit of
diff --git a/ansible/ b/ansible/
--- /dev/null
+++ b/ansible/
@@ -0,0 +8,6 @@
+def load_json(filename):
+    with open(filename) as json_file:
+        data = json.load(json_file)
+    return data


  • The following three commands will import a remote svn repository into a local git repository:
$ mkdir pymmlib && cd pymmlib
$ git svn init -t tags -b branches -T trunk
$ git svn fetch


  • Example:
$ cat ~/.gitconfig
    name = Christoph Champ
    email =
    default = simple
    lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
    lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
    lg3 = log --graph --abbrev-commit --decorate --all \
          --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)'
    lg = !"git lg1"
[url ""]
    insteadOf =

See also

External links