Using Git for version control Micah Taylor Date

advertisement
Using Git for version control
Micah Taylor
Date
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 installed
Need 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 directory
C:\Program Files (x86)\Git\
✤
rebase -b 0x64000000 bin/libsvn_repos-1-0.dll
rebase -b 0x64200000 bin/libneon-25.dll
How git works
main.c
calc.h
calc.c
local files
"working tree"
add, rm
+button.h
- action.h
staged changes
"index"
commit
master
fix bug
fix layout
tracked changes
local git repo
push
pull
dev branch
master
fix bug
tracked changes
remote git repo
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 commit
Will 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 name
The 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
Questions?
Download