5. Git commands
command description
git clone url [dir] copy a git repository so you can add to it
git add files adds file contents to the staging area
git commit records a snapshot of the staging area
git status view the status of your files in the
working directory and staging area
git diff shows diff of what is staged and what is
modified but un-staged
git pull fetch from a remote repo and try to
merge into the current branch
git push push your new branches and data to a
remote repository
others: init, reset, branch, checkout, merge, log, tag
6. Typical Development Workflow
Get the code
git clone some-repo git pull
Modify Code
Cerate Delete/Edit
Save the changes
git add git commit -m "message"
Sync with remote
git pull git push
7. Branch VS Tag
Branch Tags
• A branch is just a line of • Milestone in the life of
development project
• “Branch head” mean a • Read Only, i.e. reference
reference to the most to a fixed commit id
recent commit on a branch
8. Merge, The Blessing!!
Some merge Strategies
Resolve This can only resolve two heads
Recursive Default strategy when pulling or merging one branch
Octopus More than two branches
Ours/Theirs Just mark as merged
No-commit Do not create a new commit automatically
10. Resolve Conflict
Resolve
• Decide not to actions!
merge
• $ git merge --abort
• Resolve the
• Edit the files into
conflicts
shape then commit
Conflict
11. Client is always right!!
Git allows you to use git locally and use SVN as a remote repository
Create Git clone of Subversion repo
• $ git svn clone -s svn://example.com/repo
Update from SVN
• $ git svn rebase
Commit to SVN
• $ git svn dcommit
13. Merge Commands
Merge branches fixes and enhancement to the current branch, making an octopus merge:
$ git merge fixes enhancements
Merge branch obsolete into the current branch, using ours merge strategy:
$ git merge -s ours obsolete
Merge branch partial into the current branch, but do not make a new commit automatically:
$ git merge --no-commit partial
Cancel a merge:
$ git merge --abort
14. Cancel/Fix a commit
From latest to some point
$ git reset –<hard/soft> <where>
…..
Edit
…….
$ git add ....
$ git commit -c ORIG_HEAD
Some commit in the past
$ git revert <commit>
Fix latest commit
$ git commit --amend
15. Partial commit
You made several unrelated changes to the same file
$ git add -p
<Opens up an interactive session>
<Choose which hunk of each patch to add to the index>
16. Pulling into a dirty tree
• git stash save, git pull, git stash pop
17. Suspend work for a fix
• git stash save, do the fix, commit, git stash pop
19. Moving work to a branch
Switch to (Create) the “v1.12"
branch
• git checkout v1.12[git merge master]
• Or git checkout -b v1.12
Forcibly move master back to
early stage
• git branch -f master HEAD^^^