SlideShare a Scribd company logo
1 of 16
Download to read offline
GIT: Basics, Branching and
Tricks for SVN Users
v 0.1a
Petar Denev, SoftServe Bulgaria, February 2016
●
GIT - the stupid content tracker*
●
GIT Basics
●
GIT Workflows
●
Branching
●
The “GIT Everyday” scenario + Tips
●
Common commands and usage
●
Training Task
*man git ]; )
2
Training Agenda
●
Slang for “unpleasant person”
●
Made from Linux Kernel Hackers ]; )
●
Distributed revision control system focused on data integrity, and support for distributed, non-
linear workflows
●
Supports rapid branching and merging
●
Provides a local copy of the entire development history, changes are imported as additional
development branches, and can be merged as a locally developed branch.
●
Snapshots directory trees of files
●
Implements several merging strategies:
– Resolve – 3-way merging
– Recursive - default when pulling or merging one branch
– Octopus - default when merging more than two heads
3
GIT - the stupid content tracker
●
Data Structures
Git has two datastructures: a mutable index (also called stage or cache) that caches
information about the working directory and the next revision to be committed; and an
immutable, append-only object database.
4
●
Data Structures
Git has two datastructures: a mutable index (also called stage or cache) that caches
information about the working directory and the next revision to be committed; and an
immutable, append-only object database.
●
Data Structures
Git has two datastructures: a mutable index (also called stage or cache) that caches
information about the working directory and the next revision to be committed; and an
immutable, append-only object database.
Object database contains four types of objects:
●
blob (binary large object) – just file content - no file
name, time stamps, or other metadata.
●
tree – describes a snapshot of the source tree - a
list of file names, some filetype bits, a blob or tree
object, symbolic link, or directory's contents.
●
commit - object linking tree objects together into a
history
●
tag - a container that contains reference to another
object and can hold additional meta-data related to
another object
5
●
References - every object in the Git database which is not referred to may be cleaned up
by using a garbage collection command, or automatically.
– heads -refers to an object locally.
– remotes -refers to an object which exists in a
remote repository.
– stash -refers to an object not yet committed.
– meta -e.g. a configuration in a bare repository,
user rights.
– tags -explained in previous slide
GIT compared to SVNCore Concepts:
- Centralized version control focuses on
synchronizing, tracking, and backing up files.
- Distributed version control focuses on
sharing changes; every change has a guid or
unique id.
- Recording/Downloading and applying a change
are separate steps (in a centralized system,
they happen together).
- Distributed systems have no forced structure.
You can create “centrally administered” locations
or keep everyone as peers.
New Terms:
push: send a change to another repository
pull: grab a change from a repository
Key Advantages:
- local sandbox. It works offline
- FAST. Diffs, commits and reverts are all done locally.
- Branching and merging is easy
- Less management and easy to get running
Key disadvantages: you still need a backup
https://git.wiki.kernel.org/index.php/GitSvnCrashCourse
Before doing your first clone, the service should be configured with these
commands:
git config -–global user.name <name> //Define author name
git config –-global user.email <email> //Define author email
git config –-global –-edit //Manually edit the global config file
Lets clone: git clone https://github.com/petardenev/training
Extended repository history: git log –-graph --decorate
Add all new files and/or directories: git add -A
Submit to version control: git commit -m “<mesage>”
Push to master: git push
7
GIT Basics
8
GIT Workflow
●
Centralized workflow – same as SVN
●
Distributed worflows
– Integration Manager workflow
– Dictator and Lieutenants Workflow
– GIThub workflow
9
GIT Branches
● What a Branch is:
Git stores a commit objects with a pointers to the
snapshot of the content(filesystem like),
the author and message metadata, and zero or more
pointers to the commit
or commits that were the direct parents of this
commit:
zero parents for the first commit, one parent for a
normal commit,
and multiple parents for a commit that results from a
merge of two or more branches
● Remote branches – references to remote
repositories/tags
● Git fetch VS git checkout
●
Task: add function to complete the feature,
then merge to master
1) switch to feature branch
●
git checkout $BRANCH
2) do the changes
3) commit
GIT Everyday
● git commit -a -m '$BRANCH done'
4) push your changes
● git push
5) push rejected ?!?!
WTH? Options here?
●
DON'T USE git push –force !
●
Try to merge changes, clone the new repo in a new directory and review the
changes done
●
rebase the local repository to be up-to-date with the latest changes and then
commit yours and push to master
●
stash your changes, pull new code, stash apply
6) decided to merge
●
git merge master $BRANCH
7) can't merge, must stash changes
●
git stash
●
git pull
●
git stash apply
8) stash apply results in merge – can't track, better rebase
9) The Golden Rule of Rebasing
Never use it on public branches!
The rebase moves all of the commits in master onto the tip of feature.
The problem is that this only happened in your repository.
All of the other developers are still working with the original master.
Since rebasing results in brand new commits,
Git will think that your master branch’s history
has diverged from everybody else’s.
10) When to use rebase?
Rebase preserves the order of changesets,
and still commits your changes!
Thus – use it only if you're 1000000% sure
noone else works on the repository
at the time of push
Common commands and usage
to clone >> git clone <repo>
a specific branch only >> git clone -b my-branch <repo>
to add all, no matter files or directories >> git add -A
to check current situation in the repo >> git status
to commit in 1 line >> git commit -m ' $commit_message '
to publish changes >> git push
to change working branch >> git checkout $BRANCHNAME
to undo last commit with a new one >> git revert <commit>
to remove a file from stage(leaving it in the same directory) >> git reset <file>
to view which files would be removed >> git clean -n
to amend last commit >> git commit --amend
to rebase current branch onto <base> >> git rebase <base>
to view diff from last commit >> git diff HEAD
to reset last commit >> git reset
to reset, overwriting all changes >> git reset –hard
to reset, deleting all changes after commit >> git reset –hard <commit>
Training Task ?!?! open for advice,
should we get all the info in action
or ?!?
Thank you!
US OFFICES EUROPE OFFICES
Austin, TX
Fort Myers, FL
Lehi, UT
Newport Beach, CA
Waltham, MA
Bulgaria
Germany
Netherlands
Poland
Russia
Sweden
Ukraine
United Kingdom
www.softserveinc.com

More Related Content

What's hot

EGit 3.0 and beyond
EGit 3.0 and beyondEGit 3.0 and beyond
EGit 3.0 and beyondmsohn
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answersDeepQuest Software
 
News from Git in Java Land
News from Git in Java LandNews from Git in Java Land
News from Git in Java Landmsohn
 
Git_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGit_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGandhi Ramu
 
Git Terminologies
Git TerminologiesGit Terminologies
Git TerminologiesYash
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - GitCarlo Bernaschina
 
Common Git Commands
Common Git CommandsCommon Git Commands
Common Git CommandsHTS Hosting
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
introduction in version control system
introduction in version control systemintroduction in version control system
introduction in version control systemBiga Gaber
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-BryanLearningTech
 
Git Workflow
Git WorkflowGit Workflow
Git WorkflowGary Yeh
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 

What's hot (20)

EGit 3.0 and beyond
EGit 3.0 and beyondEGit 3.0 and beyond
EGit 3.0 and beyond
 
01 git interview questions &amp; answers
01   git interview questions &amp; answers01   git interview questions &amp; answers
01 git interview questions &amp; answers
 
Version controll.pptx
Version controll.pptxVersion controll.pptx
Version controll.pptx
 
News from Git in Java Land
News from Git in Java LandNews from Git in Java Land
News from Git in Java Land
 
Git learning
Git learningGit learning
Git learning
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGit_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_Guidewire
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Formation git
Formation gitFormation git
Formation git
 
Version Control System - Git
Version Control System - GitVersion Control System - Git
Version Control System - Git
 
Common Git Commands
Common Git CommandsCommon Git Commands
Common Git Commands
 
Git Tricks
Git TricksGit Tricks
Git Tricks
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git 101
Git 101Git 101
Git 101
 
introduction in version control system
introduction in version control systemintroduction in version control system
introduction in version control system
 
Git Training
Git TrainingGit Training
Git Training
 
Git tutorial git branches 20131206-Bryan
Git tutorial   git branches 20131206-BryanGit tutorial   git branches 20131206-Bryan
Git tutorial git branches 20131206-Bryan
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 

Similar to GIT_training_SoftServeBulgaria2016

Similar to GIT_training_SoftServeBulgaria2016 (20)

Git and Github - A primer
Git and Github - A primerGit and Github - A primer
Git and Github - A primer
 
Git introduction
Git introductionGit introduction
Git introduction
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 
Git slides
Git slidesGit slides
Git slides
 
Git more done
Git more doneGit more done
Git more done
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-it
 
Learning git
Learning gitLearning git
Learning git
 
Git-Basics
Git-BasicsGit-Basics
Git-Basics
 
Git github
Git githubGit github
Git github
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git workshop
Git workshopGit workshop
Git workshop
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Lets git to it
Lets git to itLets git to it
Lets git to it
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 

GIT_training_SoftServeBulgaria2016

  • 1. GIT: Basics, Branching and Tricks for SVN Users v 0.1a Petar Denev, SoftServe Bulgaria, February 2016
  • 2. ● GIT - the stupid content tracker* ● GIT Basics ● GIT Workflows ● Branching ● The “GIT Everyday” scenario + Tips ● Common commands and usage ● Training Task *man git ]; ) 2 Training Agenda
  • 3. ● Slang for “unpleasant person” ● Made from Linux Kernel Hackers ]; ) ● Distributed revision control system focused on data integrity, and support for distributed, non- linear workflows ● Supports rapid branching and merging ● Provides a local copy of the entire development history, changes are imported as additional development branches, and can be merged as a locally developed branch. ● Snapshots directory trees of files ● Implements several merging strategies: – Resolve – 3-way merging – Recursive - default when pulling or merging one branch – Octopus - default when merging more than two heads 3 GIT - the stupid content tracker
  • 4. ● Data Structures Git has two datastructures: a mutable index (also called stage or cache) that caches information about the working directory and the next revision to be committed; and an immutable, append-only object database. 4 ● Data Structures Git has two datastructures: a mutable index (also called stage or cache) that caches information about the working directory and the next revision to be committed; and an immutable, append-only object database. ● Data Structures Git has two datastructures: a mutable index (also called stage or cache) that caches information about the working directory and the next revision to be committed; and an immutable, append-only object database. Object database contains four types of objects: ● blob (binary large object) – just file content - no file name, time stamps, or other metadata. ● tree – describes a snapshot of the source tree - a list of file names, some filetype bits, a blob or tree object, symbolic link, or directory's contents. ● commit - object linking tree objects together into a history ● tag - a container that contains reference to another object and can hold additional meta-data related to another object
  • 5. 5 ● References - every object in the Git database which is not referred to may be cleaned up by using a garbage collection command, or automatically. – heads -refers to an object locally. – remotes -refers to an object which exists in a remote repository. – stash -refers to an object not yet committed. – meta -e.g. a configuration in a bare repository, user rights. – tags -explained in previous slide
  • 6. GIT compared to SVNCore Concepts: - Centralized version control focuses on synchronizing, tracking, and backing up files. - Distributed version control focuses on sharing changes; every change has a guid or unique id. - Recording/Downloading and applying a change are separate steps (in a centralized system, they happen together). - Distributed systems have no forced structure. You can create “centrally administered” locations or keep everyone as peers. New Terms: push: send a change to another repository pull: grab a change from a repository Key Advantages: - local sandbox. It works offline - FAST. Diffs, commits and reverts are all done locally. - Branching and merging is easy - Less management and easy to get running Key disadvantages: you still need a backup https://git.wiki.kernel.org/index.php/GitSvnCrashCourse
  • 7. Before doing your first clone, the service should be configured with these commands: git config -–global user.name <name> //Define author name git config –-global user.email <email> //Define author email git config –-global –-edit //Manually edit the global config file Lets clone: git clone https://github.com/petardenev/training Extended repository history: git log –-graph --decorate Add all new files and/or directories: git add -A Submit to version control: git commit -m “<mesage>” Push to master: git push 7 GIT Basics
  • 8. 8 GIT Workflow ● Centralized workflow – same as SVN ● Distributed worflows – Integration Manager workflow – Dictator and Lieutenants Workflow – GIThub workflow
  • 9. 9 GIT Branches ● What a Branch is: Git stores a commit objects with a pointers to the snapshot of the content(filesystem like), the author and message metadata, and zero or more pointers to the commit or commits that were the direct parents of this commit: zero parents for the first commit, one parent for a normal commit, and multiple parents for a commit that results from a merge of two or more branches ● Remote branches – references to remote repositories/tags ● Git fetch VS git checkout
  • 10. ● Task: add function to complete the feature, then merge to master 1) switch to feature branch ● git checkout $BRANCH 2) do the changes 3) commit GIT Everyday ● git commit -a -m '$BRANCH done' 4) push your changes ● git push 5) push rejected ?!?! WTH? Options here?
  • 11. ● DON'T USE git push –force ! ● Try to merge changes, clone the new repo in a new directory and review the changes done ● rebase the local repository to be up-to-date with the latest changes and then commit yours and push to master ● stash your changes, pull new code, stash apply 6) decided to merge ● git merge master $BRANCH 7) can't merge, must stash changes ● git stash ● git pull ● git stash apply
  • 12. 8) stash apply results in merge – can't track, better rebase 9) The Golden Rule of Rebasing Never use it on public branches! The rebase moves all of the commits in master onto the tip of feature. The problem is that this only happened in your repository. All of the other developers are still working with the original master. Since rebasing results in brand new commits, Git will think that your master branch’s history has diverged from everybody else’s.
  • 13. 10) When to use rebase? Rebase preserves the order of changesets, and still commits your changes! Thus – use it only if you're 1000000% sure noone else works on the repository at the time of push
  • 14. Common commands and usage to clone >> git clone <repo> a specific branch only >> git clone -b my-branch <repo> to add all, no matter files or directories >> git add -A to check current situation in the repo >> git status to commit in 1 line >> git commit -m ' $commit_message ' to publish changes >> git push to change working branch >> git checkout $BRANCHNAME to undo last commit with a new one >> git revert <commit> to remove a file from stage(leaving it in the same directory) >> git reset <file> to view which files would be removed >> git clean -n to amend last commit >> git commit --amend to rebase current branch onto <base> >> git rebase <base> to view diff from last commit >> git diff HEAD to reset last commit >> git reset to reset, overwriting all changes >> git reset –hard to reset, deleting all changes after commit >> git reset –hard <commit>
  • 15. Training Task ?!?! open for advice, should we get all the info in action or ?!?
  • 16. Thank you! US OFFICES EUROPE OFFICES Austin, TX Fort Myers, FL Lehi, UT Newport Beach, CA Waltham, MA Bulgaria Germany Netherlands Poland Russia Sweden Ukraine United Kingdom www.softserveinc.com