This document provides an overview of a Git training course titled "Git-4-Geeks". It introduces Git and its history, explaining how Linus Torvalds created Git as a replacement for BitKeeper. It then covers common Git commands like init, clone, add, commit, branch, merge, rebase, and resolve conflicts. It discusses distributed version control and branching workflows. It also addresses tagging, remote repositories, and resolving merge conflicts. The goal is to teach attendees the fundamentals of using Git through scenario-based problems and solutions.
4. GEEK ACADEMY
2013
G
GIT
In software development, Git / tɡɪ / is a distributed version control and
source code management (SCM) system with an emphasis on speed. Initially designed and
developed by Linus Torvalds for Linux kernel development, Git has since been adopted by
many other projects.
5. GEEK ACADEMY
2013
Git History
o Linux submitting patches model is quite interesting & unique in that time
o Linus hates CVS so much, he never believe in it
o He was in doomed maintaining Linux Kernel using Tarball + patch
o BitMover offer BitKeeper free usage. BitKeeper saved his life, but just for a while
o BitKeeper has a very strict Software License. People start to get upset
o Politics happened. Linus needs a replacement for BitKeeper
o Key criteria are:
o Needs to be Distributed SCM, like BitKeeper
o Needs to be highly Performance. 3 seconds max to apply a patch
o Guaranteed what goes in comes out correctly.
6. GEEK ACADEMY
2013
Git History
• Nothing matches the criteria. Linus decided to creates his own SCM, Git.
• After the 2.6.12-rc2 Linux kernel development release, he make an announce:
“I’m not going to touch linux until I have a
replacement of BitKeepers” -- Linus Torvalds
7. GEEK ACADEMY
2013
Git History
• Kernel 2.6.12 release was managed by Git
• Junio Harmano, major contributor was responsible for Git 1.0 release on 21 Dec 2005
• He remains as the project’s maintainer
• Linus on Git, Google Tech Talk: http://www.youtube.com/watch?v=4XpnKHJAok8
18. GEEK ACADEMY
2013
Problem3: How to make a commit?
$ git status
$ echo ‘hello world’ >> file1.txt
$ git status
$ git add file1.txt
$ git status
$ git commit -m “my first commit”
23. GEEK ACADEMY
2013
Git diff
$ git add file1.txt
$ git status
# Changes to be committed:# (use "git rm
--cached <file>..." to unstage)## new file:
file1.txt
32. GEEK ACADEMY
2013
S
GIT BRANCHING
- GIT branching is super easy & lightweight
- Branching is just a ref (AKA. pointer)
- SVN Branching is very heavyweight.
- Heavy enough so you wouldn’t want to create a branch unless it’s
super necessary
33. GEEK ACADEMY
2013
Problem#: How to create a new branch?
$ git branch feature1
$ git branch
$ git checkout feature1
$ git branch
$ git tree
64. GEEK ACADEMY
2013
1. A & B clone from same repo
2. A add feature1, commit and push; B add feature2, commit and push
3. A add feature3, commit and push;
3. A add feature3, commit and push;
3. A add feature3, commit and push;
69. GEEK ACADEMY
2013
Problem#: How to diff with remote branch?
$ git fetch;
$ git diff origin/master
$ git diff ...origin/master
$ git diff ..origin/master
70. GEEK ACADEMY
2013
Problem#: You want to pull but you are not
ready to commit?
$ git reset --hard HEAD~1
$ echo ‘experiment an idea’ >> feature3.txt
$ cat feature3.txt
$ git status
$ git pull origin master
STASH to rescue
71. GEEK ACADEMY
2013
Problem#: How to stash changes?
$ git stash
$ git status
$ git pull origin master
$ git stash pop
Warning!: GIT STASH can create conflicts!
74. GEEK ACADEMY
2013
Problem#: What to do when you forgot to
create a feature branch?
$ git checkout master
$ touch feature6.txt
$ git add feature6.txt
$ git commit -m “complete feature6”
75. GEEK ACADEMY
2013
Problem#: What to do when you forgot to
create a feature branch?
$ git branch feature6
$ git tree --all
$ git reset --hard origin/master
$ git tree --all
98. GEEK ACADEMY
2013
Feature Branch vs Branch by Abstraction
• Feature Branch == Poor man’s modular architect
• Feature toggle + Branch by abstraction
• Feature branch suffers when two team members start working on two different feature branches for
too long. git rebase origin/develop every day wont help much
99. GEEK ACADEMY
2013
Summary
• Git is a very cool & powerful tool
• Once you understand its basic fundamental, you’ll start fall in love with its infinite potential
• Keep calm and geek on!
git add to make the files trackable and prepare them for the next commit
git add to make the files trackable and prepare them for the next commit
Git add (to INDEX)
git status; git diff diff is a diff between WT and INDEX? what does that mean is to be shown next.
but diff shows NOTHING!?!
but diff shows NOTHING!?!
but diff shows NOTHING!?!
git diff
INDEX is a snapshot of time. # Changes to be committed :# (use "git rm --cached <file>..." to unstage)# # new file: file2.txt # Changes not staged for commit :# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)# # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt
INDEX is a snapshot of time. - try git diff again - readd and commit by using git commit -am # Changes to be committed :# (use "git rm --cached <file>..." to unstage)# # new file: file2.txt # Changes not staged for commit :# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)# # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt # modified: file2.txt
git checkout, git reset have more to come!
- Merging SVN branches is another hard topic
git add to make the files trackable and prepare them for the next commit
git add to make the files trackable and prepare them for the next commit
HEAD~1 == head -1
git checkout master git merge feature3 #input merge commit message & save git tree
What is rebase? rebase is to rewrite history.
You still have to resolve it! clone [email_address] :schalermthai/git_training_with_conflicts.git and try resolve conflicts with both merge and rebase!
origin is an default ALIAS
check git hub
setup a new git repo. Add github collaborator as necessary
B and A will have to pull first before push
origin is an default ALIAS
setup a new git repo. Add github collaborator as necessary
setup a new git repo. Add github collaborator as necessary
setup a new git repo. Add github collaborator as necessary
$ git diff remote/origin This shows the incoming remote changes as deletions; any commits in your local repository are shown as additions. $ git diff ...remote/origin Shows incoming remote changes as additions; the triple-dot excludes changes committed to your local repository. $ git diff ..remote/origin Shows incoming remote changes as additions; the double-dot includes changes committed to your local repository as deletions (since they are not yet pushed).
You can’t PULL and you aren’t ready to commit! STASH to rescue
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
Warning!: GIT STASH can create conflicts!
A friend deleted a branch you used to hold reference