Post on 06-Feb-2018
What is git?
✤ Version control software
✤ Records changes to text files
✤ Used for tracking code projects
Why use git?
✤ Distributed version control
✤ Each copy is a ‘real’ copy
✤ Good toolkit
✤ Very easy to branch
✤ Very easy to merge
✤ Advanced capabilities
Installing
✤ Debian & Ubuntu: apt-get install git
✤ Fedora: yum install git
✤ Arch: pacman -S git
✤ Linux users might also want gitk and git-svn
✤ Mac OS X: already installedNeed gitk? http://www.git-scm.com/download/mac
✤ Windows: http://www.git-scm.com/download/win
Windows issues
✤ Shell settings, ssh client, line endings
✤ Broken dlls for git svn
✤ Fix: run git shell as Admin
✤ Go to git install directoryC:\Program Files (x86)\Git\
✤ rebase -b 0x64000000 bin/libsvn_repos-1-0.dllrebase -b 0x64200000 bin/libneon-25.dll
How git works
local files"working tree"
staged changes"index"
tracked changeslocal git repo
main.ccalc.hcalc.c - action.h
+button.h
tracked changesremote git repo
fix layout
fix bug
master
fix bug
master
dev branchadd, rm commit
push
pull
How git works
✤ Clone a remote repository
✤ Basic local workflow
✤ Change a file
✤ Stage the file for commit
✤ Commit and write a log message
✤ Push or pull remote repository
Sharing is caring
✤ Can easily copy repositories: git clone url
✤ Can pull from remote repository: git pull
✤ Can push to remote repository: git push
Using SVN
✤ Set of scripts allow git to access SVN
✤ Copy SVN repo: git svn clone url
✤ Pull from SVN: git svn rebase
✤ Push to SVN: git svn dcommit
Staging a commit
✤ Git has an staging step for preparing a commit
✤ Stage changes for commit: git add file
✤ Stage files for removal: git rm file
✤ Submit staged changes to repo: git commitWill ask for a commit message
✤ The staging area is called the ‘index’
Helpful info
✤ Working tree changes: git diff
✤ Repo status: git status
✤ Revert to last commit: git reset --hard
✤ gitk can be used to see your tree (use gitk --all for all branches)
✤ Each commit has a SHA-1 has as an ID
✤ The repo’s data and config is stored in .git
Branching
✤ Create a branch: git branch nameThe new branch is created at the current branch
✤ Switch branches: git checkout branchName
✤ Commits are attached to the current branch
Merging
✤ Merge two branches together: git merge other_branch
✤ Merge other_branch to current branch
Rebase
✤ Copy changes between branches
✤ git rebase dest source
✤ Copy changes from branch source to branch dest
Rebase onto
✤ Copy only a portion of a branch
✤ git rebase --onto dest begin end
✤ Copy commits from begin to end to dest branch
✤ Does not copy begin, does copy end
✤ Result must be captured in a new branch: git branch rebaseName