SlideShare a Scribd company logo
1 of 37
Download to read offline
WP COS Meetup
Git 101- An Introduction
to Version Control using Git
11/24/15
If you are new to Version Control you are probably thinking it is
something like WordPress post revisions or a daily back-up in that you
save a copy of your project sequentially over time.
(It’s very linear)
And you would be partly right…
What is Version Control?
A B C D
The purpose of something like revisions and backups is to restore your
project to an earlier instance
What is Version Control?
A B C D
Restore
Each snapshot is an instance of a point in time. It is very linear.
This is not the case with a Version Control System such as Git.
( Although you can use it that way.)
The purpose of a Version Control System like Git is to assist you in the
development of your project, not simply restoring it if issues occur.
When Git stores a snapshop of your project (called commits) it also
stores which previous instance you made changes to.
Branching
A B D G
C E F
H I
This results in a non linear instance structure.
It looks complicated, but it results in an extremely powerful concept called
Branching
Branching is the heart and soul of what makes something like Git so
powerful.
Branching
Feature Branch
Master Branch
Branching allows you (and others) to work on parts of your
project independent of the other parts.
Then, when you are ready, you can “merge” your part back into
the main project.
Branching
A B
C D
E F- - - - - - - - - - - - - - -
You can have as many other branches as you want,
but you will always have a master branch
Basic Git Workflow
From the command line:
Staging Area
The staging area stores information about what will go into your
next commit. It’s sometimes referred to as the “index”, but it’s also
common to refer to it as the staging area.
Working Directory (your Project Directory)
The working directory is a single checkout of one version of the
project. These files are pulled out of the compressed database in
the Git directory and placed on disk for you to use or modify.
Basic Git Workflow:
1. Modify (add) files in working directory
2. Stage your modified files
3. Commit the staged files to the repo
Git Repo
Where Git stores the
metadata and object database
for your project. This is the
most important part of Git, and
it is what is copied when you
clone a repository from
another computer.
Resides in the .git directory of
your project root.
The easiest way to install it is to use the
Github Desktop app.
https://desktop.github.com/
This will install the app and also provide a command line
interface as well.
(I’ll be using the windows version, but Mac version is fine)
Git Basics
Create a local repo
Git stores everything in
repositories. So we need to
create one, in your Project
directory create the repo:
Note:
1. I’ll be using the command line, but
everything I do can be done from the GUI.
2. The .git directory is hidden normally by
Windows.
Your project directory is called
the working directory in Git
From the command line:
> git init
> git status
Git status tells you the status of
the files in the working directory
including what branch you are
working on.
We have no files so lets create a
couple.
> git status
Files are either tracked or untracked. Untracked files - any
files in your working directory that were not in your last
snapshot and are not in your staging area. Tracked files are
files git has or will save in the snapshot called a commit.
> git add <filename>
Before we can take a snapshot of
our project, we have to tell git
what files to track. We do this
with the add command:
We could also use wildcards:
> git add <filename>
> git add *
> git commit
To commit all the files in the your
staging area to your local repo
and take a snapshot of the
current instance of your project,
you commit.
The message is important
because it helps you recall what
you did. Make the message mean
something.
> git commit –m “message”
> git commit
When you have added all the files
in your staging area to the repo
and there are no untracked files,
your working directory is clean.
There is nothing for git to do.
The Three Stages of Files
Important!!
Git has 3 main states that your tracked files can reside in:
Modified means that you have changed the file but have not committed
it to your staging area yet.
Staged means that you have marked a modified file in its current
version to go into your next commit snapshot.
Committed means that the data is safely stored in your local db (repo).
Basic Git Workflow
From the command line:
Staging Area
The staging area stores information about what will go into your
next commit. It’s sometimes referred to as the “index”, but it’s also
common to refer to it as the staging area.
Working Directory (your Project Directory)
The working directory is a single checkout of one version of the
project. These files are pulled out of the compressed database in
the Git directory and placed on disk for you to use or modify.
Basic Git Workflow:
1. Modify (add) files in working directory
2. Stage your modified files
3. Commit the staged files to the repo
Git Repo
Where Git stores the
metadata and object database
for your project. This is the
most important part of Git, and
it is what is copied when you
clone a repository from
another computer.
Resides in the .git directory of
your project root.
Lets do some work
Let’s modify our readme.txt file.
To keep it simple lets just add a
second line.
Be sure to do a git add and commit.
Some more changes
Let’s change the second line.
Save, add, and commit it.
> Git log
We have made a few commits at
this point how do we see them?
As you can see the commit
messages start to play an
important role. But what about
those numbers before the commit
messages.
> git log –oneline
Use the –oneline flag
These are the ID’s git uses to keep track of the
commits.
(They’re actually each a hash, but that is another
discussion)
Some more changes
Let’s add a third line line.
Save, add, and commit it.
Opps, that wasn’t right, now what?
Opps, now what?
We made a mistake, what do we
do? If it is simple like this, correct
the file and save a new commit.
But what if we had tried a whole
new feature, with like 30 changed
files, and we need to go back?
We can reset git to the commit
we want to revert to.
> git reset --hard b2d50c6
B2d50c6 is the ID git uses to track commits.
There’s a better way
Remember we talked about
branches? Up until now we have
been making all our changes in
our master branch.
That really doesn’t leverage the
true power of git; Branches.
So let’s try again, this time using
branches.
Branches
Remember, branching allows you
to work on parts of your project
independent of the other parts.
To create a branch:
To switch to a branch:
All at once:
> git checkout <branch_name>
> git branch <branch_name>
> git checkout -b <branch_name>
More changes
Lets add another file, say
details.txt
Save, add and commit it.
Even More changes
Lets make a few more changes
and commits.
And lets use a better log
> git log –oneline --decorate
Now we know what branch the commit was on.
HEAD is just a pointer to the current commit
on the current branch.
Oh no, bugs
Now while we are working on
details.txt we are told of a bug in
readme.txt Lets fix that. But it isn’t
part of what we are doing in this
branch so lets create a new
branch in which to fix it.
But we are currently in
myfirstbranch so we need to
switch to master first, then create
it.
Fix the bugs
We made the necessary fixes
and committed them.
Status
We did a bunch of things lets see
what we have commits on three
branches.
We are on branch bugfixes.
What happened to myfirstbranch?
Myfirstbranch
It is still there, but we have to
switch to it.
bugfixes
Visually
Visually it looks like this.
myfirstbranch
Master Branch A B C D
E F G
H I
> Git merge <branch>
Now we want to merge these bug
fixes back into the master branch
so we can give it to our client.
Will merge <branch_name> into
the current branch.
So let’s switch to master and
merge bugfixes.
> git merge <branch_name>
Visually
Now master and bugfixes are still
independent of each other but
look identical.
bugfixes
myfirstbranch
Master Branch D
E F G
H I
H I
H & I are not
new commits
Another change
Let’s switch back to myfirstbranch
and make a change to the
readme.txt file.
> Git merge myfirstbranch
Now we want to merge
myfirstbranch into the master
branch.
> git merge myfirstbranch
Visually
Master contains all the changes,
merged.
bugfixes
myfirstbranch
Master Branch D
E F G
H I
H I E F G------------------------------------------------
-------------------------------------------
Deleting unnecessary branches
Suppose now we try to re-factor
myfirstbranch and it just isn’t
working. We may have made a
dozen commits to it but just no
joy. What do we do?
Simple we just delete the branch.
Create a new one and try again.
This preserves our master branch
> git branch -D <branch>
Discussion & Best practices
Those are the basics for using git.
There is so much more.
Public and Private on-line repositories
Working in teams
Git diff
Advanced workflows
Can anyone say Git201?

More Related Content

What's hot

SessionThree_IntroductionToVersionControlSystems
SessionThree_IntroductionToVersionControlSystemsSessionThree_IntroductionToVersionControlSystems
SessionThree_IntroductionToVersionControlSystemsHellen Gakuruh
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and githubAderemi Dadepo
 
Version control system
Version control systemVersion control system
Version control systemAndrew Liu
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Gitphuongvohuy
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitE Carter
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucketMedhat Dawoud
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & GitJason Byrne
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginnersbryanbibat
 

What's hot (18)

SessionThree_IntroductionToVersionControlSystems
SessionThree_IntroductionToVersionControlSystemsSessionThree_IntroductionToVersionControlSystems
SessionThree_IntroductionToVersionControlSystems
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
An Introduction to Git
An Introduction to GitAn Introduction to Git
An Introduction to Git
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 
Git commands
Git commandsGit commands
Git commands
 
Version control system
Version control systemVersion control system
Version control system
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucket
 
Gittalk
GittalkGittalk
Gittalk
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginners
 

Similar to Git 101 - An introduction to Version Control using Git

Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)Yeasin Abedin
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
BSADD-Git-TRAINING
BSADD-Git-TRAININGBSADD-Git-TRAINING
BSADD-Git-TRAININGbsadd
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with GitIvano Malavolta
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfbadrfathallah2
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfAmarnadh36
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Simplilearn
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git_tutorial.pdf
Git_tutorial.pdfGit_tutorial.pdf
Git_tutorial.pdfAliaaTarek5
 

Similar to Git 101 - An introduction to Version Control using Git (20)

Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)
 
Git for developers
Git for developersGit for developers
Git for developers
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Version controll.pptx
Version controll.pptxVersion controll.pptx
Version controll.pptx
 
git.ppt
git.pptgit.ppt
git.ppt
 
Git
GitGit
Git
 
BSADD-Git-TRAINING
BSADD-Git-TRAININGBSADD-Git-TRAINING
BSADD-Git-TRAINING
 
Bsadd training-git
Bsadd training-gitBsadd training-git
Bsadd training-git
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git github
Git githubGit github
Git github
 
Git basics
Git basicsGit basics
Git basics
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git_tutorial.pdf
Git_tutorial.pdfGit_tutorial.pdf
Git_tutorial.pdf
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 

Recently uploaded

Test Automation with Gen AI_Final_Presentation
Test Automation with Gen AI_Final_PresentationTest Automation with Gen AI_Final_Presentation
Test Automation with Gen AI_Final_PresentationUiPathCommunity
 
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsVision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsRoxana Stingu
 
Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Shubham Pant
 
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)Internet 2.0 Conference
 
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSLESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSlesteraporado16
 
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...Aligning Testing Objectives with Overall Project Goals for Successful Outcome...
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...Anju21552
 
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSTYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSedrianrheine
 
Bio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxBio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxnaveenithkrishnan
 
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...APNIC
 
Computer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteComputer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteMavein
 
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024Jan Löffler
 
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfLESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfmchristianalwyn
 
Discussing Potential of Submarine Cables Causing Internet Blackout in Ghana
Discussing Potential of Submarine Cables Causing Internet Blackout in GhanaDiscussing Potential of Submarine Cables Causing Internet Blackout in Ghana
Discussing Potential of Submarine Cables Causing Internet Blackout in GhanaDesmond Israel
 

Recently uploaded (13)

Test Automation with Gen AI_Final_Presentation
Test Automation with Gen AI_Final_PresentationTest Automation with Gen AI_Final_Presentation
Test Automation with Gen AI_Final_Presentation
 
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsVision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
 
Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024
 
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)
Internet 2.0 Conference (Event Information Deck | Dec'24 - Mar'25)
 
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSLESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
 
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...Aligning Testing Objectives with Overall Project Goals for Successful Outcome...
Aligning Testing Objectives with Overall Project Goals for Successful Outcome...
 
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSTYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
 
Bio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxBio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptx
 
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
 
Computer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteComputer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a Website
 
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
 
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfLESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
 
Discussing Potential of Submarine Cables Causing Internet Blackout in Ghana
Discussing Potential of Submarine Cables Causing Internet Blackout in GhanaDiscussing Potential of Submarine Cables Causing Internet Blackout in Ghana
Discussing Potential of Submarine Cables Causing Internet Blackout in Ghana
 

Git 101 - An introduction to Version Control using Git

  • 1. WP COS Meetup Git 101- An Introduction to Version Control using Git 11/24/15
  • 2. If you are new to Version Control you are probably thinking it is something like WordPress post revisions or a daily back-up in that you save a copy of your project sequentially over time. (It’s very linear) And you would be partly right… What is Version Control? A B C D
  • 3. The purpose of something like revisions and backups is to restore your project to an earlier instance What is Version Control? A B C D Restore Each snapshot is an instance of a point in time. It is very linear. This is not the case with a Version Control System such as Git. ( Although you can use it that way.)
  • 4. The purpose of a Version Control System like Git is to assist you in the development of your project, not simply restoring it if issues occur. When Git stores a snapshop of your project (called commits) it also stores which previous instance you made changes to. Branching A B D G C E F H I This results in a non linear instance structure.
  • 5. It looks complicated, but it results in an extremely powerful concept called Branching Branching is the heart and soul of what makes something like Git so powerful. Branching
  • 6. Feature Branch Master Branch Branching allows you (and others) to work on parts of your project independent of the other parts. Then, when you are ready, you can “merge” your part back into the main project. Branching A B C D E F- - - - - - - - - - - - - - - You can have as many other branches as you want, but you will always have a master branch
  • 7. Basic Git Workflow From the command line: Staging Area The staging area stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area. Working Directory (your Project Directory) The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify. Basic Git Workflow: 1. Modify (add) files in working directory 2. Stage your modified files 3. Commit the staged files to the repo Git Repo Where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer. Resides in the .git directory of your project root.
  • 8. The easiest way to install it is to use the Github Desktop app. https://desktop.github.com/ This will install the app and also provide a command line interface as well. (I’ll be using the windows version, but Mac version is fine) Git Basics
  • 9. Create a local repo Git stores everything in repositories. So we need to create one, in your Project directory create the repo: Note: 1. I’ll be using the command line, but everything I do can be done from the GUI. 2. The .git directory is hidden normally by Windows. Your project directory is called the working directory in Git From the command line: > git init
  • 10. > git status Git status tells you the status of the files in the working directory including what branch you are working on. We have no files so lets create a couple.
  • 11. > git status Files are either tracked or untracked. Untracked files - any files in your working directory that were not in your last snapshot and are not in your staging area. Tracked files are files git has or will save in the snapshot called a commit.
  • 12. > git add <filename> Before we can take a snapshot of our project, we have to tell git what files to track. We do this with the add command: We could also use wildcards: > git add <filename> > git add *
  • 13. > git commit To commit all the files in the your staging area to your local repo and take a snapshot of the current instance of your project, you commit. The message is important because it helps you recall what you did. Make the message mean something. > git commit –m “message”
  • 14. > git commit When you have added all the files in your staging area to the repo and there are no untracked files, your working directory is clean. There is nothing for git to do.
  • 15. The Three Stages of Files Important!! Git has 3 main states that your tracked files can reside in: Modified means that you have changed the file but have not committed it to your staging area yet. Staged means that you have marked a modified file in its current version to go into your next commit snapshot. Committed means that the data is safely stored in your local db (repo).
  • 16. Basic Git Workflow From the command line: Staging Area The staging area stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area. Working Directory (your Project Directory) The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify. Basic Git Workflow: 1. Modify (add) files in working directory 2. Stage your modified files 3. Commit the staged files to the repo Git Repo Where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer. Resides in the .git directory of your project root.
  • 17. Lets do some work Let’s modify our readme.txt file. To keep it simple lets just add a second line. Be sure to do a git add and commit.
  • 18. Some more changes Let’s change the second line. Save, add, and commit it.
  • 19. > Git log We have made a few commits at this point how do we see them? As you can see the commit messages start to play an important role. But what about those numbers before the commit messages. > git log –oneline Use the –oneline flag These are the ID’s git uses to keep track of the commits. (They’re actually each a hash, but that is another discussion)
  • 20. Some more changes Let’s add a third line line. Save, add, and commit it. Opps, that wasn’t right, now what?
  • 21. Opps, now what? We made a mistake, what do we do? If it is simple like this, correct the file and save a new commit. But what if we had tried a whole new feature, with like 30 changed files, and we need to go back? We can reset git to the commit we want to revert to. > git reset --hard b2d50c6 B2d50c6 is the ID git uses to track commits.
  • 22. There’s a better way Remember we talked about branches? Up until now we have been making all our changes in our master branch. That really doesn’t leverage the true power of git; Branches. So let’s try again, this time using branches.
  • 23. Branches Remember, branching allows you to work on parts of your project independent of the other parts. To create a branch: To switch to a branch: All at once: > git checkout <branch_name> > git branch <branch_name> > git checkout -b <branch_name>
  • 24. More changes Lets add another file, say details.txt Save, add and commit it.
  • 25. Even More changes Lets make a few more changes and commits. And lets use a better log > git log –oneline --decorate Now we know what branch the commit was on. HEAD is just a pointer to the current commit on the current branch.
  • 26. Oh no, bugs Now while we are working on details.txt we are told of a bug in readme.txt Lets fix that. But it isn’t part of what we are doing in this branch so lets create a new branch in which to fix it. But we are currently in myfirstbranch so we need to switch to master first, then create it.
  • 27. Fix the bugs We made the necessary fixes and committed them.
  • 28. Status We did a bunch of things lets see what we have commits on three branches. We are on branch bugfixes. What happened to myfirstbranch?
  • 29. Myfirstbranch It is still there, but we have to switch to it.
  • 30. bugfixes Visually Visually it looks like this. myfirstbranch Master Branch A B C D E F G H I
  • 31. > Git merge <branch> Now we want to merge these bug fixes back into the master branch so we can give it to our client. Will merge <branch_name> into the current branch. So let’s switch to master and merge bugfixes. > git merge <branch_name>
  • 32. Visually Now master and bugfixes are still independent of each other but look identical. bugfixes myfirstbranch Master Branch D E F G H I H I H & I are not new commits
  • 33. Another change Let’s switch back to myfirstbranch and make a change to the readme.txt file.
  • 34. > Git merge myfirstbranch Now we want to merge myfirstbranch into the master branch. > git merge myfirstbranch
  • 35. Visually Master contains all the changes, merged. bugfixes myfirstbranch Master Branch D E F G H I H I E F G------------------------------------------------ -------------------------------------------
  • 36. Deleting unnecessary branches Suppose now we try to re-factor myfirstbranch and it just isn’t working. We may have made a dozen commits to it but just no joy. What do we do? Simple we just delete the branch. Create a new one and try again. This preserves our master branch > git branch -D <branch>
  • 37. Discussion & Best practices Those are the basics for using git. There is so much more. Public and Private on-line repositories Working in teams Git diff Advanced workflows Can anyone say Git201?