Very simple git intro

git config

%%bash

git config --global --get user.name git config --global --get user.email

Basic commands

git clone <repo>
git status
git log
git commit
git add <file>
git rm <file>
git diff <file>
git push

In [ ]:
%%bash

git status

In [ ]:
%%bash

git log

In [ ]:
%%bash

git show

In [ ]:
%%writefile foo.md

Fetchez la vache

In [ ]:
%%bash

git add foo.md

In [ ]:
%%bash

git st

In [ ]:
%%bash

git diff foo.md

In [ ]:
%%bash

git diff git_intro.ipynb

In [ ]:
%%bash

git rm -f foo.md

In [ ]:
%%bash

git st

GitHub workflow

Fork → Branch → Write → PR

Fork

git clone https://github.com/<username>/git_intro_demo.git

Branch


In [ ]:
%%bash

git branch new_post

In [ ]:
%%bash

git checkout new_post

In [ ]:
%%writefile my_new_post.md

# Q: What is the meaning of life?
# A: 42

In [ ]:
%%bash

git st

In [ ]:
%%bash

git add my_new_post.md

In [ ]:
%%bash

git st

In [ ]:
%%bash

git ci -m "Adding my new post." my_new_post.md

In [ ]:
%%bash

git push

In [ ]:
%%bash

git push --set-upstream origin new_post

PR ready!? What now?


In [ ]:
%%bash

git remote --verbose

In [ ]:
%%bash

git remote add upstream https://github.com/ocefpaf/git_intro_demo.git
git remote --verbose

Let go to https://github.com/USERNAME/git_intro_demo.git

And see id we can merge this!

Useful resources

aliases

[alias]
    pull = pull --ff-only
    st = status -s
    ci = commit
    co = checkout
    diff = diff --word-diff
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
    ls = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
    filelog = log -u
    la = "!git config -l | grep alias | cut -c 7-"
    grep = grep -Ii

Important things I did not cover:

  • Undoing stuff
  • Checking out to a previous commit
  • SVN/HG git mappings (if you ar coming from Subversion or Mercurial)

Git aware prompt

Markdown