SlideShare une entreprise Scribd logo
1  sur  56
{
Git Basics
A simple introductory workshop
for the GDC SDK team
Mateusz Gałażyn
October 29th, 2014
1. What is git? Why do you need it?
2. Repository structure
3. Basic workflow
 Exercises!
4. Branches
 Exercises!
5. Basic merging
 Exercises!
6. Remotes
 Exercises!
7. Graphical User Interface
Outline
An open source distributed version
control system (VCS).
What is Git?
Imagine a situation, when you’re writing your code...
... and suddenly after deployment on a production ...
Why do you need a VCS?
Why do you need a VCS?
Only working backup can save your life now
You can store your backups in separate folders...
... but it’s not convenient
Why do you need a VCS?
Version Control System will do it for you!
A good VSC has to:
 Prevent data loss
 Provide history of who did what
 Allow commit messages
 Ease the creation of diffs / patches
 Be fast and scalable
What is Git?
 Git is distributed – (almost) everything is local – you can work
offline and have backups on your local machine
 Git is fast – again, most of your work is local, and network
interactions are compressed and minimal
Why Git?
As you learn Git, try to clear your
mind of the things you may know
about other VCSs.
Git stores and thinks about
information much differently than
other systems and doing so will help
you avoid subtle confusion when
using the tool.
Before we get into Git...
 A repository is a collection of commits
Repository structure
 A repository is a collection of commits
 A commit is a snapshot of your working tree at some point of
time
Repository structure
 A repository is a collection of commits
 A commit is a snapshot of your working tree at some point of
time
 A working tree is a directory (and sub-directories) which has
repository associated with it
Repository structure
At the beginning of work with Git we are creating empty
repository (or cloning an existing one)
Basic Git workflow
Repository
During our work, we are modyfing file structure inside a
Working Tree
Basic Git workflow
Repository
Working
Tree
Changes from the working tree are not registered in the
repository directly. Instead, they are registered in the Index. The
other name for it is a „staging area”.
Basic Git workflow
Repository
Working
Tree
Index
Changes to the working
tree are registered in the
index using git add
Once the index contains everything you want to commit, you
record the changes in the repository
Basic Git workflow
Repository
Working
Tree
Index
Changes to the working
tree are registered in the
index using
Changes are commited to
the repository from the
state of the index using
git commit
git add
git checkout
Basic Git workflow
Repository
Working
Tree
Index
Changes to the working
tree are registered in the
index using
Changes are commited to
the repository from the
state of the index using
Earlier states of the working
tree may be checked out
from the repository at any
time using
git commit
git add
Install Git:
1. Go to git-scm.com
2. Download installer and execute it
3. (IMPORTANT) In the Adjusting your PATH environment
select first option „Use Git from Git Bash only”
4. For the rest of options you can leave default choices
Exercise #0
TODO:
1. Create an empty repository
2. Make changes in the file system and add to index
3. Commit
4. Make changes in the file system
5. Reset to the clean state
6. Make changes in the file system and add to the index
7. Commit
8. Diff between commits
9. Checkout the first commit
Exercise #1
Before we start we need to configure Git
Exercise #1
git config --global user.name "your-name"
git config --global user.email "mail@youremail.com"
1. Create an empty repository locally
2. Make changes in the file system and add them to index
3. Commit
Exercise #1
git init .
echo ”first changes” > file1.txt
echo ”a very important message” > file2.txt
git add .
git commit –m ”my first commit”
dot adds whole
directory at
once
commit message is
obligatory
4. Make changes in the file system
5. Reset only non-staged changes to the clean state (latest commit)
You can use instead of dot, a path to a specific file.
To reset working tree and index:
Exercise #1
echo ”foo foo bar bar” > file2.txt
git status
git diff
git checkout .
git reset --hard HEAD
a name for the the latest
checked out commit
6. Make changes in the file system and add them to the index
7. Commit
Current repository structure:
Exercise #1
echo ”second changes” > file1.txt
git add .
git commit -m ”my second commit”
my first
commit
my second
commit
HEAD
6. Diff between commits
7. Checkout the first commit
Current repository structure:
Exercise #1
git log --oneline
git diff 933734d f618b84
Your hash ids
will be different
git checkout 933734d
my first
commit
my second
commit
HEAD
So what happens when you checkout a commit from a past, and
make another commit?
Detached HEAD???
You are ending in the Detached HEAD state.
After some time such commits in the detached head can be
pruned by the garbage collector and your work will be lost.
Detached HEAD???
This can be fixed, requires merging (sometimes a lot).
Golden rule: Always work on the latest commits.
Avoid detached HEADS. Use branches instead.
Detached HEAD???
A branch (reference, ref) is also another name of a commit. It is
the name for the last commit in the line. By default, git creates
master branch:
Branches
At each point you can easily create your new branch using
following command:
Now we have two branches (pointing for the same commit):
Branches
git branch devel
Using branches you can for example store working releases of an
application in a master branch and development line in devel one:
... let’s try them out!
Branches
TODO:
1. Create new branch
2. Commit changes
3. Create another branch
4. Diff between branches
5. Delete branch
Exercise #2
1. Create new branch
2. Commit changes
Current repository structure:
Exercise #2
git checkout master
git branch branch-1
git checkout branch-1
echo ”b1” >> file1.txt
echo ”foo bar bar” > file2.txt
git add .
git commit -m ”b1”
my first
commit
my second
commit
master
b1
branch-1 HEAD
3. Create another branch
Current repository structure:
Exercise #2
git branch branch-2
eit checkout branch-2
echo ”b2” >> file1.txt
git add .
git commit –m ”b2”
my first
commit
my second
commit
master
b1
branch-1
HEAD
b2
branch-2
4. Diff between branches
5. Delete branch
Current repository structure:
Exercise #2
git checkout master
git branch -d branch-2
git diff branch-1 branch-2
my first
commit
my second
commit
master
b1
branch-1
HEAD
What to do when we want to join few different branches?
to the rescue!
Most common merge types:
 Fast-forward merge
 3-way merge
 Rebase
Basic merging
git merge
Let’s assume we have the
following repository
structure:
We would like to merge
devel into master
Fast-Forward merge
Let’s assume we have the
following repository
structure:
We would like to merge
devel into master
Fast forward merge moves
master pointer forward to
the commit 4 and no new
commit is created
Fast-Forward merge
Let’s assume we have the
following repository structure:
We would like to merge
devel into master
3-way merge
Let’s assume we have the
following repository structure:
We would like to merge
devel into master
With Git you can merge files
containing conflicts (changed
in commits 5 & 6), manually
decide which changes should
be applied and create merge
commit (commit 6).
3-way merge
Let’s assume we have the following repository structure and we
would like to merge feature into master:
With rebase you can apply commits from feature branch on top of
master and preserve linear structure of repository.
Rebase
TODO:
1. Make a fast-forward merge
2. Undo ff-merge
3. Make commit on master
4. Make 3-way merge
5. Undo merge commit
6. Make rebase
Exercise #3
1. Make a fast-forward merge
Before After
Exercise #3
my first
commit
my second
commit
master
b1
branch-1
HEAD
my first
commit
my second
commit
master
b1
branch-1
HEAD
git checkout master
git merge branch-1
2. Undo fast-forward merge
It moves the HEAD pointer back by 1 commit and resets working tree
3. Make commit on master
Exercise #3
my first
commit
my second
commit
master
b1 branch-1
HEAD
git reset --hard HEAD~1
echo ”a very unimportant message” > file2.txt
git add file2.txt
git commit -m ”m1”
m1
4. Make 3-way merge
We have merge confilct (contents of file2.txt):
After correcting file2.txt, execute following commands:
Exercise #3
git checkout master
git merge branch-1
git status
<<<<<<< HEAD
a very unimportant message
=======
foo bar bar
>>>>>>> branch-1
git add file2.txt
git commit -m ”merge commit”
Current repository structure:
Exercise #3
my first
commit
my second
commit
master
b1
branch-1
HEAD
m1
merge
commit
5. Undo 3-way merge
Repository structure after reset:
Exercise #3
my first
commit
my second
commit
master
b1 branch-1
HEAD
git reset --hard HEAD~1
m1
6. Make git rebase
We have merge confilct (contents of file2.txt):
After correcting file2.txt, execute following commands:
Exercise #3
git checkout branch-1
git rebase master
<<<<<<< HEAD
a very unimportant message
=======
foo bar bar
>>>>>>> branch-1
git add file2.txt
git rebase --continue
git checkout master
git merge branch-1
Repository structure after rebase:
Exercise #3
my first
commit
my second
commit
master
b1
branch-1
HEAD
m1
Git remote repositories can be accessed via almost every
protocol: SSH, HTTP(S), FTP, Local, Git...
 You can clone remote repository using
 You can publish your changes using
 You can pull changes on remote to your local repo using
Remote repositories
git clone
git push
git pull
TODO:
1. Create new empty local repository
2. Copy local repository to a remote server
3. Add remote to your repository
4. Push changes to a remote repository
5. Clone remote repository
Exercise #4
1. Create new empty local repository
Create new directory with your last name and go there with git bash
2. Copy local repository to a remote server
Copy this directory to pol-mgalazyngw
3. Add remote to your repository
Navigate using git bash to your repository from previous exercises
4. Push changes to a remote repository
Exercise #4
git init --bare
git remote add origin file:////pol-mgalazyn/gw/lastname
git push --set-upstream origin master
From now you can push commited changes to the remote using only:
5. Clone remote repository
Using git bash go to directory one level higher
Exercise #4
git push
git clone file:////pol-mgalazyn/gw/someoneslastname
GitLab configuration
(if you haven’t done it already)
TODO:
1. Generate SSH keys for authentication without password
When prompted for file to save key - confirm default value with Enter
When prompted for passphrase - leave empty
2. Paste SSH Public key into GitLab
a. Go to https://prod-pol-git/ and log in
b. Navigate to Profile settings > SSH Keys > Add SSH Key
c. Open with notepad file C:Usersyouruser.sshid_rsa.pub
d. Copy its contents and paste to Key field in GitLab
e. Enter Title whatever you want and click Add Key
Exercise #5
ssh-keygen -t rsa
Honestly, I bet you were not convinced by Git Bash.
There are other more user-friendly options with GUI on the
market:
 SmartGit
 EGit (Eclipse plugin)
 TortoiseGit
 SourceTree
 ... and many more
Graphical User Interface
Recap - command sequence
Questions?
( you can always ask me directly or send an e-mail to:
mgalazyn@microstrategy.com )
git push –f overwrites the remote branch with the state of the branch you are pushing, so using it you can accidentally overwrite
commits you want to keep
Don’t be scared of Git! :)

Contenu connexe

Tendances (20)

Git 101
Git 101Git 101
Git 101
 
Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615Intro to Git DevOps Tally Presentation 101615
Intro to Git DevOps Tally Presentation 101615
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Hello git
Hello git Hello git
Hello git
 
Git in 5 Minutes
Git in 5 MinutesGit in 5 Minutes
Git in 5 Minutes
 
Tài liệu sử dụng GitHub
Tài liệu sử dụng GitHubTài liệu sử dụng GitHub
Tài liệu sử dụng GitHub
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
آموزش کار با GIT
آموزش کار با GITآموزش کار با GIT
آموزش کار با GIT
 
From svn to git
From svn to gitFrom svn to git
From svn to git
 
Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / Github
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
 
Git
GitGit
Git
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 
Github
GithubGithub
Github
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Github - Le Wagon Melbourne
Github - Le Wagon MelbourneGithub - Le Wagon Melbourne
Github - Le Wagon Melbourne
 
Git101
Git101Git101
Git101
 
Git
GitGit
Git
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git learn from scratch
Git learn from scratchGit learn from scratch
Git learn from scratch
 

Similaire à Git workshop

Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Introduce to Git and Jenkins
Introduce to Git and JenkinsIntroduce to Git and Jenkins
Introduce to Git and JenkinsAn Nguyen
 
Git - Version Control System
Git - Version Control SystemGit - Version Control System
Git - Version Control SystemNamig Hajiyev
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Intro to git (UT biocomputing 2015)
Intro to git (UT biocomputing 2015)Intro to git (UT biocomputing 2015)
Intro to git (UT biocomputing 2015)chenghlee
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git John Tighe
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists Steven Hamblin
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitRasan Samarasinghe
 

Similaire à Git workshop (20)

Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Introduce to Git and Jenkins
Introduce to Git and JenkinsIntroduce to Git and Jenkins
Introduce to Git and Jenkins
 
Git - Version Control System
Git - Version Control SystemGit - Version Control System
Git - Version Control System
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 
Intro to git (UT biocomputing 2015)
Intro to git (UT biocomputing 2015)Intro to git (UT biocomputing 2015)
Intro to git (UT biocomputing 2015)
 
Git basics
Git basicsGit basics
Git basics
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
 
Git introduction workshop for scientists
Git introduction workshop for scientists Git introduction workshop for scientists
Git introduction workshop for scientists
 
Git SCM
Git SCMGit SCM
Git SCM
 
Learning git
Learning gitLearning git
Learning git
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git Init (Introduction to Git)
Git Init (Introduction to Git)Git Init (Introduction to Git)
Git Init (Introduction to Git)
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Git github
Git githubGit github
Git github
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
 
git2.ppt
git2.pptgit2.ppt
git2.ppt
 

Dernier

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Dernier (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Git workshop

  • 1. { Git Basics A simple introductory workshop for the GDC SDK team Mateusz Gałażyn October 29th, 2014
  • 2. 1. What is git? Why do you need it? 2. Repository structure 3. Basic workflow  Exercises! 4. Branches  Exercises! 5. Basic merging  Exercises! 6. Remotes  Exercises! 7. Graphical User Interface Outline
  • 3. An open source distributed version control system (VCS). What is Git?
  • 4. Imagine a situation, when you’re writing your code... ... and suddenly after deployment on a production ... Why do you need a VCS?
  • 5. Why do you need a VCS? Only working backup can save your life now
  • 6. You can store your backups in separate folders... ... but it’s not convenient Why do you need a VCS?
  • 7. Version Control System will do it for you! A good VSC has to:  Prevent data loss  Provide history of who did what  Allow commit messages  Ease the creation of diffs / patches  Be fast and scalable What is Git?
  • 8.  Git is distributed – (almost) everything is local – you can work offline and have backups on your local machine  Git is fast – again, most of your work is local, and network interactions are compressed and minimal Why Git?
  • 9. As you learn Git, try to clear your mind of the things you may know about other VCSs. Git stores and thinks about information much differently than other systems and doing so will help you avoid subtle confusion when using the tool. Before we get into Git...
  • 10.  A repository is a collection of commits Repository structure
  • 11.  A repository is a collection of commits  A commit is a snapshot of your working tree at some point of time Repository structure
  • 12.  A repository is a collection of commits  A commit is a snapshot of your working tree at some point of time  A working tree is a directory (and sub-directories) which has repository associated with it Repository structure
  • 13. At the beginning of work with Git we are creating empty repository (or cloning an existing one) Basic Git workflow Repository
  • 14. During our work, we are modyfing file structure inside a Working Tree Basic Git workflow Repository Working Tree
  • 15. Changes from the working tree are not registered in the repository directly. Instead, they are registered in the Index. The other name for it is a „staging area”. Basic Git workflow Repository Working Tree Index Changes to the working tree are registered in the index using git add
  • 16. Once the index contains everything you want to commit, you record the changes in the repository Basic Git workflow Repository Working Tree Index Changes to the working tree are registered in the index using Changes are commited to the repository from the state of the index using git commit git add
  • 17. git checkout Basic Git workflow Repository Working Tree Index Changes to the working tree are registered in the index using Changes are commited to the repository from the state of the index using Earlier states of the working tree may be checked out from the repository at any time using git commit git add
  • 18. Install Git: 1. Go to git-scm.com 2. Download installer and execute it 3. (IMPORTANT) In the Adjusting your PATH environment select first option „Use Git from Git Bash only” 4. For the rest of options you can leave default choices Exercise #0
  • 19. TODO: 1. Create an empty repository 2. Make changes in the file system and add to index 3. Commit 4. Make changes in the file system 5. Reset to the clean state 6. Make changes in the file system and add to the index 7. Commit 8. Diff between commits 9. Checkout the first commit Exercise #1
  • 20. Before we start we need to configure Git Exercise #1 git config --global user.name "your-name" git config --global user.email "mail@youremail.com"
  • 21. 1. Create an empty repository locally 2. Make changes in the file system and add them to index 3. Commit Exercise #1 git init . echo ”first changes” > file1.txt echo ”a very important message” > file2.txt git add . git commit –m ”my first commit” dot adds whole directory at once commit message is obligatory
  • 22. 4. Make changes in the file system 5. Reset only non-staged changes to the clean state (latest commit) You can use instead of dot, a path to a specific file. To reset working tree and index: Exercise #1 echo ”foo foo bar bar” > file2.txt git status git diff git checkout . git reset --hard HEAD a name for the the latest checked out commit
  • 23. 6. Make changes in the file system and add them to the index 7. Commit Current repository structure: Exercise #1 echo ”second changes” > file1.txt git add . git commit -m ”my second commit” my first commit my second commit HEAD
  • 24. 6. Diff between commits 7. Checkout the first commit Current repository structure: Exercise #1 git log --oneline git diff 933734d f618b84 Your hash ids will be different git checkout 933734d my first commit my second commit HEAD
  • 25. So what happens when you checkout a commit from a past, and make another commit? Detached HEAD???
  • 26. You are ending in the Detached HEAD state. After some time such commits in the detached head can be pruned by the garbage collector and your work will be lost. Detached HEAD???
  • 27. This can be fixed, requires merging (sometimes a lot). Golden rule: Always work on the latest commits. Avoid detached HEADS. Use branches instead. Detached HEAD???
  • 28. A branch (reference, ref) is also another name of a commit. It is the name for the last commit in the line. By default, git creates master branch: Branches
  • 29. At each point you can easily create your new branch using following command: Now we have two branches (pointing for the same commit): Branches git branch devel
  • 30. Using branches you can for example store working releases of an application in a master branch and development line in devel one: ... let’s try them out! Branches
  • 31. TODO: 1. Create new branch 2. Commit changes 3. Create another branch 4. Diff between branches 5. Delete branch Exercise #2
  • 32. 1. Create new branch 2. Commit changes Current repository structure: Exercise #2 git checkout master git branch branch-1 git checkout branch-1 echo ”b1” >> file1.txt echo ”foo bar bar” > file2.txt git add . git commit -m ”b1” my first commit my second commit master b1 branch-1 HEAD
  • 33. 3. Create another branch Current repository structure: Exercise #2 git branch branch-2 eit checkout branch-2 echo ”b2” >> file1.txt git add . git commit –m ”b2” my first commit my second commit master b1 branch-1 HEAD b2 branch-2
  • 34. 4. Diff between branches 5. Delete branch Current repository structure: Exercise #2 git checkout master git branch -d branch-2 git diff branch-1 branch-2 my first commit my second commit master b1 branch-1 HEAD
  • 35. What to do when we want to join few different branches? to the rescue! Most common merge types:  Fast-forward merge  3-way merge  Rebase Basic merging git merge
  • 36. Let’s assume we have the following repository structure: We would like to merge devel into master Fast-Forward merge
  • 37. Let’s assume we have the following repository structure: We would like to merge devel into master Fast forward merge moves master pointer forward to the commit 4 and no new commit is created Fast-Forward merge
  • 38. Let’s assume we have the following repository structure: We would like to merge devel into master 3-way merge
  • 39. Let’s assume we have the following repository structure: We would like to merge devel into master With Git you can merge files containing conflicts (changed in commits 5 & 6), manually decide which changes should be applied and create merge commit (commit 6). 3-way merge
  • 40. Let’s assume we have the following repository structure and we would like to merge feature into master: With rebase you can apply commits from feature branch on top of master and preserve linear structure of repository. Rebase
  • 41. TODO: 1. Make a fast-forward merge 2. Undo ff-merge 3. Make commit on master 4. Make 3-way merge 5. Undo merge commit 6. Make rebase Exercise #3
  • 42. 1. Make a fast-forward merge Before After Exercise #3 my first commit my second commit master b1 branch-1 HEAD my first commit my second commit master b1 branch-1 HEAD git checkout master git merge branch-1
  • 43. 2. Undo fast-forward merge It moves the HEAD pointer back by 1 commit and resets working tree 3. Make commit on master Exercise #3 my first commit my second commit master b1 branch-1 HEAD git reset --hard HEAD~1 echo ”a very unimportant message” > file2.txt git add file2.txt git commit -m ”m1” m1
  • 44. 4. Make 3-way merge We have merge confilct (contents of file2.txt): After correcting file2.txt, execute following commands: Exercise #3 git checkout master git merge branch-1 git status <<<<<<< HEAD a very unimportant message ======= foo bar bar >>>>>>> branch-1 git add file2.txt git commit -m ”merge commit”
  • 45. Current repository structure: Exercise #3 my first commit my second commit master b1 branch-1 HEAD m1 merge commit
  • 46. 5. Undo 3-way merge Repository structure after reset: Exercise #3 my first commit my second commit master b1 branch-1 HEAD git reset --hard HEAD~1 m1
  • 47. 6. Make git rebase We have merge confilct (contents of file2.txt): After correcting file2.txt, execute following commands: Exercise #3 git checkout branch-1 git rebase master <<<<<<< HEAD a very unimportant message ======= foo bar bar >>>>>>> branch-1 git add file2.txt git rebase --continue git checkout master git merge branch-1
  • 48. Repository structure after rebase: Exercise #3 my first commit my second commit master b1 branch-1 HEAD m1
  • 49. Git remote repositories can be accessed via almost every protocol: SSH, HTTP(S), FTP, Local, Git...  You can clone remote repository using  You can publish your changes using  You can pull changes on remote to your local repo using Remote repositories git clone git push git pull
  • 50. TODO: 1. Create new empty local repository 2. Copy local repository to a remote server 3. Add remote to your repository 4. Push changes to a remote repository 5. Clone remote repository Exercise #4
  • 51. 1. Create new empty local repository Create new directory with your last name and go there with git bash 2. Copy local repository to a remote server Copy this directory to pol-mgalazyngw 3. Add remote to your repository Navigate using git bash to your repository from previous exercises 4. Push changes to a remote repository Exercise #4 git init --bare git remote add origin file:////pol-mgalazyn/gw/lastname git push --set-upstream origin master
  • 52. From now you can push commited changes to the remote using only: 5. Clone remote repository Using git bash go to directory one level higher Exercise #4 git push git clone file:////pol-mgalazyn/gw/someoneslastname
  • 53. GitLab configuration (if you haven’t done it already) TODO: 1. Generate SSH keys for authentication without password When prompted for file to save key - confirm default value with Enter When prompted for passphrase - leave empty 2. Paste SSH Public key into GitLab a. Go to https://prod-pol-git/ and log in b. Navigate to Profile settings > SSH Keys > Add SSH Key c. Open with notepad file C:Usersyouruser.sshid_rsa.pub d. Copy its contents and paste to Key field in GitLab e. Enter Title whatever you want and click Add Key Exercise #5 ssh-keygen -t rsa
  • 54. Honestly, I bet you were not convinced by Git Bash. There are other more user-friendly options with GUI on the market:  SmartGit  EGit (Eclipse plugin)  TortoiseGit  SourceTree  ... and many more Graphical User Interface
  • 55. Recap - command sequence
  • 56. Questions? ( you can always ask me directly or send an e-mail to: mgalazyn@microstrategy.com ) git push –f overwrites the remote branch with the state of the branch you are pushing, so using it you can accidentally overwrite commits you want to keep Don’t be scared of Git! :)

Notes de l'éditeur

  1. I’ll explain later, what in case of git „distributed” means
  2. Blue screen of death. At this point you need to downgrade your work to the latest working version ASAP and only working backup can save your life now. But how to deal with the backups?
  3. ... browsing a large number of folders manually is not efficient
  4. Git is distributed – almost all of your work is saved in your local repository, so you do not waste time on downloading backups and you can work offline Git is fast – because the backups are in your local repository and network utilization is as little as it is possible
  5. But before we get into Git, try to clear your mind from other things you may know about other VCSs.
  6. Before we start using git, we need to know 3 most important terms in git: The first one is a repository. What is a repository in Git? I the most simple words thats just a collection of commits. Just it.
  7. What is a commit?
  8. What is a working tree? Since we know those three basic objects in Git, we can jump to the workflow.
  9. Unlike other, similar tools you may have used, Git does not commit changes directly from the working tree into the repository. Instead, changes are first registered in something called the index. think of it as a way of “confirming” your changes, one by one, before doing a commit (which records all your approved changes at once). Some find it helpful to call it instead as the “staging area”, instead of the index.
  10. If you would like to revert the changes in the working tree to a particular commit, you can do it using git checkout. This is the basic git workflow. It goes like this preety much every time. To recap, at first you are creating new repository, or cloning existing one, making changes, adding changes to index, and committing changes to the repository. Now it is the time for some practice!
  11. At first we need to install git