Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
jeremy.gobet.72@gmail.com
Agenda
1. Discover Git
2. Basic commands
3. Understand Git basics
4. Working remotely
5. Branches & workflows
6. Rewrite history
7. Other commands
8. Advanced notions
9. Conclusion
Discover Git
Connect
git help
1. Untracked
2. Staged
3. Up-to-date
4. Not staged
staged
not
Up to date
Untracked
Staged
Exit mode
vi readme.txt • ESC
git diff
Cancel
git status
• u
git commit -am "edited readme file"
Quit
git status
• :q
git log
Save & Quit
• :wq
Force Quit
• :q!
Vi cheatsheet
Cancel last changes
mode insert
• i
Exit mode
vi readme.txt • ESC
git status
Cancel
git checkout readme.txt
• u
git status
Quit
• :q
Force Quit
• :q!
Commit selection cheatsheet
Cancel & revert commits
last commit
• HEAD^
• HEAD~1
Cancel last commit 2 last commits
git reset --soft HEAD^ • HEAD^^
• HEAD~2
git rm readme.txt
git status
git commit -am "removed readme file"
git status
git log
Ignore files and folders
.gitignore
u Syntax in .gitignore file
u **.txt Ignore all files with txt extension
u *.txt Ignore all files with txt extension in root folder
u /src/data Ignore all files and folder in folder: /src/data
u /app/*.txt Ignore all files with txt extension in folder: /app
u app Ignore all files and folder named app
u !/target/.txt Ignore all everything except files with txt extension
Working remotely
A decentralized model from Linux
Git workflow
Git pull
Remote
1 2 3 4 5
origin/master
master
Local
1 2 3 4 5
Remote
1 2 3 4 5
origin/master
Git push
Remote
1 2 3
origin/master
master
Local
1 2 3 4 5
Remote
1 2 3 4 5
origin/master
Git fetch
Remote
1 2 3 4 5
origin/master
master
Local
1 2 3 4 5
Remote
1 2 3 4 5
origin/master
Git clone remote repository
cd ..
git clone git@github.com:PimsJay01/git-training.git
(reply yes to the question)
cd git-training
git remote -v
git pull origin master
SSH Keys
Exit mode
Edit file index.html (add your name) • ESC
Cancel
Commit change
• u
Quit
Check Web page on your browser
• :q
Remote
1 2 3 4
origin/master
What happened ?
Git pull in conflict
master
Local
1 2 3 4
Remote
1 2 3 4
origin/master
here is my readme
<<<<<<< HEAD
the cake is a lie. Your local change
=======
the cake is telling the truth! Remote change
>>>>>>>
4e76d3542a7eee02ec516a47600002a90a4e4b48
Visual merge tools
Vi cheatsheet
Push change
mode insert
• i
Exit mode
Resolve conflict • ESC
vi index.html (or use Visual Studio)
Cancel
add index.html
• u
git commit -m "Resolved conflict"
Quit
• :q
Force Quit
• :q!
Conflict resolved
master
Local
1 2 3
Remote
1 2 3
origin/master
master
Local
1 2 3 4
resolve conflict
Remote
1 2 3
origin/master
Git remote
Display references
git remote -v origin git@github.com:PimsJay01/git-training.git (fetch)
origin git@github.com:PimsJay01/git-training.git (push)
Delete reference
git remote remove myrepo
Edit remote URL
Remove branche
git branch -D my-branch
Create feature branch
u Demo
Feature branch & merge request
u A clean way to work with Git & branches but merge create additional commits
Workflow GitFlow
Rewrite history
Classic merge flow vs rebase flow
alice
bob
bob
Why rebasing ?
Git rebase remotely
master branch
Local branch
1 2 3
Remote master
1 2 3
origin/master
master branch
Local branch
1 2 3 4 5
origin/master
Git rebase locally
branch
2 3
Local
1 2 3
master
branch
4 5
Local Replayed
1 2 3
master
Vim cheatsheet
Rebase your branch
mode insert
from origin master • i
Exit mode
git pull --rebase origin master • ESC
Cancel
Resolve conflict
• u
vim index.html (or use Visual Studio)
Quit
git commit -am "Resolved conflict"
• :q
git status
Save & Quit
• :wq
Push your change
git push origin add_name-your-name Force Quit
• :q!
What happened ?
Hash
Remote branch
1 2 3
origin/branch
1 2 3 4 5
Remote
origin/branch
Push changes on your branch
Rejected !
Display logs
git log
Add a tag
git tag -a v0.2 -m "version 0.2"
Checkout a tag
git checkout v0.2
Git revert
2 3
Local
1 A B C
ec4a9fe
master
branch
2 3 A
Local
1 A B C
master
Git bissect
u Find the commit where a bug was introduced using Git only!
u Works by dichotomy: compares the result of a test using different commits.
u Finds the first commit where the test did not pass
Monitor
Deploy
Deploy
u Git commits are easy and fast à Commit frequently (and deal with it later)
u Git branches are cheap à Use as many as you need!
u Git ask less manual merges à The merge engine is powerful
u Git is standalone à You don’t need a server to work
u Questions ?