ict.ken.be

Delivering solid user friendly software solutions since the dawn of time.

Git Fundamentals - Notes

Categories: Tortoise

by James Kovacs

http://jameskovacs.com

  • Git created by Linus Torvalds, who also created Linux (because Bit-Keeper started asking him money)
  • Written in Perl and C

Advantages of DVCS

  • Different topologies (centralized, hierarchical, distributed)
  • Each clone is a full backup
  • Reliable branching/merging
  • Full local history (statistics, analyze regressions)
  • Deployment

Windows

Mac OSX

  • brew install git
  • DMG (http://git-scm.com/download/mac)

Linux

  • sudo apt-get install git-core (Debian/Ubuntu)
  • yum install git-core

Commands

git --version
git config --system (c:\Program Files\Git\etc\gitconfig)
git config --global (c:\Users\user\.gitconfig)
git config (stored in .git/config in each repo)

git config --global --list
git config --global help.autocorrect 1 (corrects your mispelled command)
git config --global color.ui auto
git config --global core.autocrlf true|false|input

git init

git status
git add foo.txt
git commit -m "my text"

git log

git diff dd6819..a15ec6
git diff HEAD~1..HEAD (~1 is one back from head revision)

git add -u (only adds updated files)
git add -A (all even untracked)

git checkout foo.txt (revert changes)
git reset --hard (revert all to head)
git reset --soft HEAD~1 (reorganize version)

git clean -n|-f (remove)

.gitignore
/logs/allthese.*
/bin

git clone https://foo.repo
git log --oneline | wc=1
git shortlog -sne (short name include number of commits and email)

git remote -v (where does the source come from)

git branch -r (include remote branches)

git remote add origin https://apullrequest
git fetch
git log origin/master
git merge origin/master
git branch -r

git branch --set-upstream master origin/master
git pull (shortcut of fetching and merging from an origin)
git remote add origin git@github.com:JamesKovacs/GitFundamentals.git (uses ssh key)
git push

git tag v1.0
git tag -a v1.0_with_message
git tag -s v1.0_signed
git push --tags

Protocols

  • https 80/443 https://github.com/jquery/jquery.git
  • git 9418 git://github.com/jquery/jquery.git
  • ssh 22 git@github.com:jquery/jquery.git
  • file n/a filepath

Branching, Merging, and Rebasing with Git

git log --graph --oneline --all --decorate
git config --global alias.lga "log --graph --oneline --all --decorate"
git lga
git reflog (about 30 days to get delete back)
git stash (rollback pending changes)
git stash list
git stash apply
git stash pop (apply and remove)
git stash drop
git stash branch 'feature2_additional'

git mergetool (eg. KDiff3, BeyondCompare)
git checkout bug1234
git rebase master
git rebase --continue

git branch v1.0_fixes v1.0
git checkout v1.0_fixes
git commit -am "Added fix1"
git commit -am "Added fix2"
git checkout master
git cherry-pick 6fa4324

git fetch origin master
git push
git push origin v1.0_fixes

More