SlideShare a Scribd company logo
Introduction into Git
Serhii Kartashov
December 2015
Softjourn
Internship
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Types of Version Control Systems (VCS)
Distributed Version ControlCentralized Version Control
server
client client
repo
repo repo
Fundamental Concepts
• repository
• working copy
• conflicts
• merging changes
• development (branching) model
tag dev feature
origin
git repo
git repo git repo
commit
branch
repo
git repo git repo
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
How to start working with Git
• Install Git client (see useful links at the end)
– git --version
• Config you client
– git config --global user.name “Serhii Kartashov“
– git config --global user.email Serhii.Kartashov@example.com
– git config --list (check your settings)
• Clone a branch from a repository
– git clone https://myrepo.com/repo workdir
• Initialize your local repo and link to remote repo
– git init
– git remote add <my_fork> <url>
• Use git help command
– git help clone (launches browser to display HTML with instructions on how to
use this clone command)
• You may add .gitignore file to ignore some files, i.e. <*.jar>
Life cycle of files in your repo
Saving Changes
• Adding files to stage area:
– git add <file>
– git add <directory>
– git add --all
• Commit the staged snapshot to the project
history:
– git commit -m “<message>”
– git commit –a (will open text editor - vi)
Inspecting a Repository
• Display a status of working directory and the
staging are:
– git status
• Display committed snapshots:
– git log
– git log --oneline
– git log -p <file>
– git log --stat
– git log –graph --decorate –oneline
– git log –author=“Serhii Kartashov”
Undoing Changes. revert
• Undo a committed snapshot.
– git revert <commit>
But, instead of removing the commit from the
project history, it figures out how to undo the
changes introduced by the commit and appends
a new commit with the resulting content.
Undoing Changes, reset
• edit two files, stage one
• run git reset HEAD to undo the stage
• re-stage the file and commit
• run git reset --soft HEAD~ to undo the commit
but keep the staged files; commit again
• run git reset HEAD~ to undo the commit and all
staging; commit again
• run git reset --hard HEAD~ to lose the commit
and all that work
Undoing Changes, clean
• Remove untracked files from your working
directory
– git clean –n (just shows you what may be
removed)
– git clean -f (files only)
– git clean –df (files and directories)
Rewriting history
The git commit --amend command is a
convenient way to fix up the most recent
commit.
It lets you combine staged changes with the
previous commit instead of committing it as an
entirely new snapshot.
Rewriting history, rebase
• Rebasing is the process of moving a branch to
a new base commit.
– git rebase <base>
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Development (branching) model
• Branch convention:
– master
– develop
– release-* (tags)
– hotfix-*
Using Branches, branch
The git branch command lets you create, list,
rename, and delete branches. It doesn’t let you
switch between branches or put a forked
history back together again.
– git branch (list branches)
– git branch <branch> (create new branch)
– git branch -d <branch> (delete the specified
branch)
– git branch -m <branch> (rename the current
branch to <branch>)
Using branches, checkout
The git checkout command lets you navigate
between the branches created by git branch.
– git checkout <existing-branch>
– git checkout -b <new-branch>
Using Branches, merge
The git merge command lets you take the
independent lines of development created by
git branch and integrate them into a single
branch.
– git merge <branch>
– git merge --no-ff <branch> (merge the specified
branch into the current branch, but always
generate a merge commit)
Git Work Flow Cycle
clone repo
create,
checkout
branch
make
changes
update
branch
add files
to stage
commit
staged
files
push
commits
to
repo/fork
create pull
request
Clone repository
• git clone
• git init
• git remote
Create/Checkout branch
• git branch
• git checkout
Make changes
• git add
• git reset
Update branch
• git diff
• git fetch
• git rebase
Commit changes
• git commit
Push changes to repo
• git push
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Stashing
• Stash the changes in a dirty working directory
away
– git stash
– git stash list
– git stash apply
– git stash show <stash_name>
– git stash drop <stash_name>
– git stash branch testchanges
– git stash clear
Filtering and Formatting Logs
• git shortlog
• git log --graph --oneline --decorate
• git log -3 (display only the 3 most recent
commits)
• git log --after="2014-7-1“ (by date)
• git log --author="John|Mary“
• git log --grep="JRA-228:“ (by name)
• git log -S"Hello, World!" (by content)
Useful links
• Git clients
– http://git-scm.com/downloads (required)
– https://code.google.com/p/tortoisegit/wiki/Download
• Useful Git resources
– https://www.atlassian.com/git/tutorials/setting-up-a-
repository/#!overview
– http://ndpsoftware.com/git-cheatsheet.html#loc=workspace
– https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
– Squash several Git commits into a single commit
• Git books and docs
– http://git-scm.com/book
– Command’s list http://git-scm.com/docs
– http://git-scm.com/documentation
Home Work. Git
1. Work Cycle:
1. create and init remote repository (set-url);
2. checkout branch and create new one;
3. rename branch;
4. create new files and add it to git;
5. commit changes and push them to remote repo;
6. use reset command (stage, commit, etc.)
7. use stash command (list, drop, save, pop, branch)
2. Branches:
1. copy new branch from created before (task 1);
2. apply changes in new branch and commit it (create possible
conflict between them);
3. merge changes in the second branch into first one.
Introduction into Git
Ad

More Related Content

What's hot (20)

Git basics
Git basicsGit basics
Git basics
Denys Haryachyy
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
Abdul Basit
 
Git
GitGit
Git
Omar Al-Sabek
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
Shinho Kang
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Pham Quy (Jack)
 
Git undo
Git undoGit undo
Git undo
Avilay Parekh
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
LearningTech
 
Git
GitGit
Git
Shinu Suresh
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
Jim Yeh
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
Git 101
Git 101Git 101
Git 101
jayrparro
 
01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
Edward Goikhman
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
Katie Sylor-Miller
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Shilu Shrestha
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
gittower
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Git presentation
Git presentationGit presentation
Git presentation
Vikas Yaligar
 

Similar to Introduction into Git (20)

Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
Soumen Debgupta
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
Pranesh Vittal
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
Roniel Lopez Alvarez
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
Adarsh Konchady
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
Gourav Varma
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
srinathcox
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
atishgoswami
 
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internetgit.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know abgithub ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
Gourav Varma
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
Chris Johnson
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
Gourav Varma
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
srinathcox
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
atishgoswami
 
git.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internetgit.ppt.pptx power point presentation got Google internet
git.ppt.pptx power point presentation got Google internet
rani marri
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
gdsc13
 
github ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know abgithub ppt git ppt on git hub to know ab
github ppt git ppt on git hub to know ab
infoinnext
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
Gourav Varma
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Ad

Recently uploaded (20)

Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
wareshashahzadiii
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Agentic AI Use Cases using GenAI LLM models
Agentic AI Use Cases using GenAI LLM modelsAgentic AI Use Cases using GenAI LLM models
Agentic AI Use Cases using GenAI LLM models
Manish Chopra
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
wareshashahzadiii
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Agentic AI Use Cases using GenAI LLM models
Agentic AI Use Cases using GenAI LLM modelsAgentic AI Use Cases using GenAI LLM models
Agentic AI Use Cases using GenAI LLM models
Manish Chopra
 
Ad

Introduction into Git

  • 1. Introduction into Git Serhii Kartashov December 2015 Softjourn Internship
  • 2. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 3. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 4. Types of Version Control Systems (VCS) Distributed Version ControlCentralized Version Control server client client repo repo repo
  • 5. Fundamental Concepts • repository • working copy • conflicts • merging changes • development (branching) model tag dev feature origin git repo git repo git repo commit branch repo git repo git repo
  • 6. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 7. How to start working with Git • Install Git client (see useful links at the end) – git --version • Config you client – git config --global user.name “Serhii Kartashov“ – git config --global user.email [email protected] – git config --list (check your settings) • Clone a branch from a repository – git clone https://myrepo.com/repo workdir • Initialize your local repo and link to remote repo – git init – git remote add <my_fork> <url> • Use git help command – git help clone (launches browser to display HTML with instructions on how to use this clone command) • You may add .gitignore file to ignore some files, i.e. <*.jar>
  • 8. Life cycle of files in your repo
  • 9. Saving Changes • Adding files to stage area: – git add <file> – git add <directory> – git add --all • Commit the staged snapshot to the project history: – git commit -m “<message>” – git commit –a (will open text editor - vi)
  • 10. Inspecting a Repository • Display a status of working directory and the staging are: – git status • Display committed snapshots: – git log – git log --oneline – git log -p <file> – git log --stat – git log –graph --decorate –oneline – git log –author=“Serhii Kartashov”
  • 11. Undoing Changes. revert • Undo a committed snapshot. – git revert <commit> But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content.
  • 12. Undoing Changes, reset • edit two files, stage one • run git reset HEAD to undo the stage • re-stage the file and commit • run git reset --soft HEAD~ to undo the commit but keep the staged files; commit again • run git reset HEAD~ to undo the commit and all staging; commit again • run git reset --hard HEAD~ to lose the commit and all that work
  • 13. Undoing Changes, clean • Remove untracked files from your working directory – git clean –n (just shows you what may be removed) – git clean -f (files only) – git clean –df (files and directories)
  • 14. Rewriting history The git commit --amend command is a convenient way to fix up the most recent commit. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot.
  • 15. Rewriting history, rebase • Rebasing is the process of moving a branch to a new base commit. – git rebase <base>
  • 16. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 17. Development (branching) model • Branch convention: – master – develop – release-* (tags) – hotfix-*
  • 18. Using Branches, branch The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. – git branch (list branches) – git branch <branch> (create new branch) – git branch -d <branch> (delete the specified branch) – git branch -m <branch> (rename the current branch to <branch>)
  • 19. Using branches, checkout The git checkout command lets you navigate between the branches created by git branch. – git checkout <existing-branch> – git checkout -b <new-branch>
  • 20. Using Branches, merge The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. – git merge <branch> – git merge --no-ff <branch> (merge the specified branch into the current branch, but always generate a merge commit)
  • 21. Git Work Flow Cycle clone repo create, checkout branch make changes update branch add files to stage commit staged files push commits to repo/fork create pull request Clone repository • git clone • git init • git remote Create/Checkout branch • git branch • git checkout Make changes • git add • git reset Update branch • git diff • git fetch • git rebase Commit changes • git commit Push changes to repo • git push
  • 22. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 23. Stashing • Stash the changes in a dirty working directory away – git stash – git stash list – git stash apply – git stash show <stash_name> – git stash drop <stash_name> – git stash branch testchanges – git stash clear
  • 24. Filtering and Formatting Logs • git shortlog • git log --graph --oneline --decorate • git log -3 (display only the 3 most recent commits) • git log --after="2014-7-1“ (by date) • git log --author="John|Mary“ • git log --grep="JRA-228:“ (by name) • git log -S"Hello, World!" (by content)
  • 25. Useful links • Git clients – http://git-scm.com/downloads (required) – https://code.google.com/p/tortoisegit/wiki/Download • Useful Git resources – https://www.atlassian.com/git/tutorials/setting-up-a- repository/#!overview – http://ndpsoftware.com/git-cheatsheet.html#loc=workspace – https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf – Squash several Git commits into a single commit • Git books and docs – http://git-scm.com/book – Command’s list http://git-scm.com/docs – http://git-scm.com/documentation
  • 26. Home Work. Git 1. Work Cycle: 1. create and init remote repository (set-url); 2. checkout branch and create new one; 3. rename branch; 4. create new files and add it to git; 5. commit changes and push them to remote repo; 6. use reset command (stage, commit, etc.) 7. use stash command (list, drop, save, pop, branch) 2. Branches: 1. copy new branch from created before (task 1); 2. apply changes in new branch and commit it (create possible conflict between them); 3. merge changes in the second branch into first one.

Editor's Notes

  • #8: Remote rename - Rename the remote named <old> to <new>. All remote-tracking branches and configuration settings for the remote are updated. add - Adds a remote named <name> for the repository at <url>. rm - Remove the remote named <name>. All remote-tracking branches and configuration settings for the remote are removed. set-url – Changes URL remote points to. Sets first URL remote points to matching regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If <oldurl> doesn’t match any URL, error occurs and nothing is changed. i.e. git remote set-url origin git://new.url.here
  • #22: List of all main git commands http://git-scm.com/docs
  • #24: Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command. Stash command description - http://git-scm.com/book/en/Git-Tools-Stashing save - Save your local modifications to a new stash, and run git reset --hard to revert them.  branch - Creates and checks out a new branch named <branchname> starting from the commit at which the<stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. list - List the stashes that you currently have. Each stash is listed with its name (e.g. stash@{0} is the latest stash, stash@{1} is the one before, etc.) show - Show the changes recorded in the stash as a diff between the stashed state and its original parent.  drop - Remove a single stashed state from the stash list. When no <stash> is given, it removes the latest one.  clear - Remove all the stashed states. Note that those states will then be subject to pruning, and may be impossible to recover.