• Git is a distributed version control system
  • It is a Linux community project released in 2005 as a replacement for BitKeep (proprietary) that the linux community had used prior as a VCS for the linux kernel

Snapshots not Differences

  • Unlike a lot of other VCSs, git stores snapshots not differences (called delta-based version control)
  • Delta-based version control,
  • Git’s version control (stream of snapshots),

User view

  • Users get to see three different files states and each git project has three areas
  • File states in git,
    • Modified
    • Staged
    • Committed
  • Three areas in a git project,
    • Working tree - single checkout of one version of the project
    • Staging area - a file that has information on what will go into the next commit
    • .git directory
      • Metadata
      • Object database - compressed snapshots of all files


git rm FILE
git rm --staged FILE
 
git mv from_file to_file
git log --stat
 
git log --pretty=oneline/short/full/fuller
 
git log -S function_name
 
git log -- file_name

Helpful Config Stuff

git config --global user.name ""
git config --global user.email ""
git config --global init.defaultBranch main
 
git config --list
git config user.name
 
git config --list --show-origin #see all your settings and where they are coming from

Creating aliases,

git config --global alias.staash 'stash --all'

Run a script and pretend like it’s a git command,

git config --global alias.bb !better-branch.sh
 
# ! - indicates shell script

Having an intermediate git config btw local .gitconfig and global .gitconfig,

[includeIf "gitdir:~/projects/work/"]
	path = ~/projects/work/.gitconfig
 
[includeIf "gitdir:~/projects/play/"]
	path = ~/projects/play/.gitconfig

Oldies

git blame
 
git balme -L
 
git log -L 15,26:path/to/filr
 
git log -L :<function/ entity name>:path/to/file
 
# ignore whitespace
git blame -w 
 
# ignore whitespace and detect lines moved or copied in the same commit
git blame -w -C 
 
# ignore whitespace and detect lines moved or copied in the same commit or the commit that created the file
git blame -w -C -C 
 
# ignore whitespace and detect lines moved or copied in the same commit or the commit that created the file or any commit at all
git blame -w -C -C -C

Get the person who wrote those lines

Tell git to remember the merge conflict, remember how you fixed it and fix the same merge conflict, if it occurs again in the future

git config --global rerere.enabled true

git push --force-with-lease # safer than force

git maintanance start # makes things faster

Refs

  1. “Pro Git” by Scott Chacon and Ben Straub