SlideShare a Scribd company logo
GIT
Crash Course in Version Control using Git
Compiled from various internet sources by Kishor Kumar
Git
• What You Will Learn Today
• What a VCS is
• Why using a VCS is a good idea
• Why Git is becoming, if not already, the standard
VCS of choice for developers worldwide
• Why you should care
• Git basics, including:
• How to obtain & install git
• How to use it for basic, common operations
• Where to go for more information
Git
• What is a Version Control System (VCS)?
• A way to keep track of changes to files (& folders)
• Between multiple authors (developers)
• A record of who did what, when
• Why is provided by commit messages!
• Non-distributed (Subversion, CVS)
• Server has the master repo, all commits go to the server
• Distributed (Git, Mercurial)
• Server has the master repo, but you have a copy (clone) of
the repo on your machine
• CVS, Visual Source Safe, Perforce are some others
Git
• Git is (a VCS that is)...
• An open source VCS designed for speed and
efficiency
• Better than competing tools
• Created by Linus Torvalds (for managing Linux
kernel)
• Your best insurance policy against:
• Accidental mistakes like deleting work
• Remembering what you changed, when, why
• Your hard drive blowing up*
Git
• Git is (a VCS that is)...
• Your best insurance policy against:
• Accidental mistakes like deleting work
• Remembering what you changed, when, why
• Your hard drive blowing up*
• The version control solution I recommend to
manage code of all types
• Hosted solutions include Github.com (more
widespread, more expensive) or Bitbucket.com
(cheaper, integrates with Jira)
• or running your own Git server
Git
• Getting Git
• Download the software - it's free
• http://git-scm.com/downloads
• or on Mac (homebrew), $ brew install git
• Download a GUI, optional
• http://git-scm.com/downloads/guis
• Read the manual and/or the book
• http://git-scm.com/docs
• http://git-scm.com/book
Git
• How does Git compare?
• An open source, distributed version control software
designed for speed and efficiency
• Unlike Subversion, Git is distributed.
• This means that you can use Git on your local
machine without being connected to the internet.
• Revisions (commits) you make to your local
repository are available to you only
• The next time you connect to the internet, push
your changes to a remote repository to share them
& back them up offsite & off your computer
Git
• How does Git compare?
• The distributed nature of Git makes it insanely fast,
because most things you do happen on your local
machine
• The local nature of Git makes it effortless to create
branches to isolate your work
• The local nature of Git makes it possible to coalesce
a series of changes (local commits) into a single
commit on the remote branch
Git
• Understanding Git Workflow
• Obtain a repository
• Either via git init, or git clone, or if you already have
the repo, pull changes!
• Make some edits
• Use your favorite text editor or source code IDE
• Most IDEs have Git integration, including NetBeans
• git tracks changes to binary files too: images, pdf, etc.
• Less useful though, than text-based files
• Stage your changes
• using git add
• Commit your work
• git commit -m "Always write clear commit messages!"
• Push to remote
• git push remotename localbranch:remotebranch
Understanding Git
Remote Repo
Working Directory
Index
Repository
"Staging"
"a copy of your project"
git add
git commit
git push
/ git pull
internet
your pc
"your clone of the remote repo"
your edits
git clone
Git
• First Steps: Check installation
• Check if Git is installed:
• $ git --version
• git version 1.7.10.2 (Apple Git-33)
• If not, brew install git or download the installer
• Set your Git username and email to your global
config:
• $ git config --global user.name "Geoff Hoffman"
• $ git config --global user.email
"phpguru@salientdigital.com"*
• How to enter your username and password only
once:
• https://help.github.com/articles/generating-ssh-keys
http://git-scm.com/docs/git-config
Git
• First Steps: Obtaining a repository
• Creating a repository (if one does not exist
remotely):
• $ git init
• @see http://git-scm.com/docs/git-init
• Or, cloning a remote repository:
• $ git clone https://reposite.tld/account/repo.git localdir
• $ git clone https://github.com/phpguru/phpredis.git
• localdir is optional. The repo name is used in this case.
• @see http://git-scm.com/docs/git-clone
• $ cd phpredis
• $ ls –la
• Inspect the repo configuration:
• $ vim .git/config
Git
• First Steps: Inspecting your repo
• Change Directory into the repository & issue a git
status
• $ cd path/to/repo
• $ git status
• @see http://git-scm.com/docs/git-status
• "Displays paths that have differences between the
index file and the current HEAD commit, paths that
have differences between the working tree and the
index file, and paths in the working tree that are not
tracked by Git (and are not ignored by gitignore(5))"
• @see http://git-scm.com/docs/gitignore
• In other words, shows what you added, modified or
deleted since your
last commit.
Git
• First Steps: Inspecting your repo
• Change Directory into the repository & issue a git
log
• $ cd path/to/repo
• $ git log
• $ git log --pretty=oneline
• $ git log -1
• @see http://git-scm.com/docs/git-log
• "Shows the commit logs."
• In other words, why you committed something
• Hopefully you wrote descriptive commit messages in
the past!
Git
• First Steps: Making Edits & Committing
• You can use whatever program you normally use to
edit files.
• Make a new file - newfile.txt
• Edit the file as desired
• Save it in your working directory
• $ git status
• will show the file as "Changes not staged for commit"
• $ git add newfile.txt
• $ git status
• will show newfile.txt as "Changes to be committed"
• git commit -m "Added newfile.txt as an example"
• [Master 1e77a20] Added newfile.txt as an example
• 1 file changed, 0 insertions(+), 0 deletions(-)
Git
• First Steps: Adding (staging) changes
• Change Directory into the repository & issue a git
status, then add new/modified files
• $ cd path/to/repo
• $ git add (file)
• $ git add –A
• @see http://git-scm.com/docs/git-add
• "This command updates the index using the current
content found in the working tree, to prepare the
content staged for the next commit."
• In other words, stage your added, modified or deleted
files for committing.
Git
• First Steps: Committing (staged) changes
• Change Directory into the repository & issue a git
status, then add new/modified files, then commit
them to your local repository
• $ cd path/to/repo
• $ git add (file)
• $ git commit -m "What did you change? Log messages
matter."
• @see http://git-scm.com/docs/git-commit
• "Stores the current contents of the index in a new
commit along with a log message from the user
describing the changes."
• In other words, store the added, modified or deleted
files you staged in your repository.
Git 101
Git workflow visualization
Standard Workflow
edits
git add git add git add
edits edits
git
commit
git
commit
git
commit
Repo
Work
Stage
Repo
Work
Stage
Repo
Work
Stage
Repo
--> time -->
Origin
git clone
git pull
Origin
git push
(git init)
internet
your pc
Git
• First Steps: Pushing
• At this point, none of those changes you've made have left your
computer. (You still have local "infinite undo".) Let's push those changes
to the remote repo.
• git push <repository> <refspec>
• git push origin master
• git push origin master:master
• You now have an annotated, offsite backup of the work
you performed!
• REMEMBER:
• If you never commit, you have no history.
• If you never push, you have no offsite backup.
• As a rule of thumb, commit every hour, push every day.
• There is no reason not to commit after every "logical stopping-
point" and push when a good section of work is complete, unit
tests pass, etc.
• After you commit, your colleagues can pull changes down
from the origin repository to their local working repository.
Git
• First Steps: Pushing your changes offsite
(local -> remote)
• Change Directory into the repository & issue a git
push
• $ cd path/to/repo
• $ git push origin master
• @see http://git-scm.com/docs/git-push
• "Updates remote refs using local refs, while sending
objects necessary to complete the given refs."
• In other words, send your local changes back to the
remote repo you cloned from.
Git
• First Steps: Pulling someone else's changes
(remote -> local)
• Change Directory into the repository & issue a git
pull
• $ cd path/to/repo
• $ git pull origin master
• @see http://git-scm.com/docs/git-pull
• "Incorporates changes from a remote repository into
the current branch. In its default mode, git pull is
shorthand for git fetch followed by git merge
FETCH_HEAD."
• In other words, retrieve changes made to the remote
repo and merge them into your local repo, updating
your working copy to match.
Git
Next Steps: Working smart(er)
Branch Workflow
git branch "Branch"
git checkout Branch
git checkout Master
git merge Branch
edits
git add git add git add
edits edits
git
commit
git
commit
git
commit
Master
Branch
Work
Stage
Branch
Work
Stage
Branch
Work
Stage
Master
Branch
--> time -->
Origin
git clone
git pull
Origin
git push
internet
your pc
Git 101
• Final Steps: Deploying Code
• Change Directory into the repository, list the current
tags, check the branch you're on, and tag the current
branch/revision
• $ cd path/to/repo
• $ git tag –l
• $ git branch
• $ git tag -a v1.1 -m "Tagging version 1.1 with
featurename"
• @see http://git-scm.com/docs/git-tag
• @see http://git-scm.com/book/en/Git-Basics-Tagging
• "Add a tag reference in refs/tags/, unless -d/-l/-v is given
to delete, list or verify tags. Unless -f is given, the named
tag must not yet exist. If one of -a, -s, or -u <key-id> is
passed, the command creates a tag object, and requires a
tag message."
• In other words, create a named/numbered reference to a
specific revision of the code, or list prior tags created
Git 101
• Final Steps: Deploying Code
• A tag is a special type of commit... as such, just like
any other commit, the tag only exists locally. The
final step in tagging is to push the tag to the remote
repository, just like we do with regular commits.
• $ cd path/to/repo
• $ git push origin v1.1
• $ git push origin --tags
• @see http://git-scm.com/book/en/Git-Basics-Tagging
• "By default, the git push command doesn’t transfer
tags to remote servers. You will have to explicitly push
tags to a shared server after you have created them."
• In other words, don't forget to push after tagging,
otherwise the tag only exists on your local machine.
Git 101
• Wrap Up: Review
• The most common commands you will use during a
normal day/week working with Git to manage versions
of code:
Download/Create a local repo
$ git clone
$ git init
Checking what's changed
$ git status
$ git log
Storing edits
$ git add
$ git commit
Updating your local repo
$ git pull (git fetch)
$ git branch
$ git merge
Storing changes offsite/offbox
$ git commit
$ git push
Storing changes offsite/offbox
$ git tag
$ git push

More Related Content

PDF
Git training v10
PPTX
PDF
Git - An Introduction
PPTX
Introduction to Gitlab | Gitlab 101 | Training Session
PPTX
Git 101 for Beginners
PDF
GIT | Distributed Version Control System
PPTX
Git One Day Training Notes
Git training v10
Git - An Introduction
Introduction to Gitlab | Gitlab 101 | Training Session
Git 101 for Beginners
GIT | Distributed Version Control System
Git One Day Training Notes

What's hot (20)

PDF
Github - Git Training Slides: Foundations
PDF
Learning git
PPTX
Git basics to advance with diagrams
PDF
Starting with Git & GitHub
PPTX
Introduction git
PPTX
Git and Github Session
PPTX
Git commands
PDF
JavaScript Inheritance
PDF
Introduction to Git and GitHub
PDF
A Practical Introduction to git
PPTX
Git - Basic Crash Course
PPTX
Github basics
PPTX
A successful Git branching model
PPTX
GitHub Basics - Derek Bable
PDF
Git and Github slides.pdf
PPTX
Intro to git and git hub
PPTX
Git and GitHub
ODP
Introduction to Version Control
PDF
Git 101: Git and GitHub for Beginners
KEY
Introduction To Git
Github - Git Training Slides: Foundations
Learning git
Git basics to advance with diagrams
Starting with Git & GitHub
Introduction git
Git and Github Session
Git commands
JavaScript Inheritance
Introduction to Git and GitHub
A Practical Introduction to git
Git - Basic Crash Course
Github basics
A successful Git branching model
GitHub Basics - Derek Bable
Git and Github slides.pdf
Intro to git and git hub
Git and GitHub
Introduction to Version Control
Git 101: Git and GitHub for Beginners
Introduction To Git
Ad

Viewers also liked (20)

PPT
Intro to tsql unit 3
PPT
Ppt test
PPTX
論文紹介 - EARS (Earthquake Alert and Report System): a Real Time Decision Suppo...
PPTX
Ls flumgilleon
DOCX
Wanita atau pun isteri muslim
PPT
Mobile Cloud
PPTX
Make it at your library presentation draft 6 10 13
PPTX
Building Webs Better
PDF
2012.+bol.bibliograf.++2º+trimestre
PPT
Presentation 5
PDF
Holiday cocktail party wear featuring – bebe dresses
PPTX
Vigo presentation 07/12/2011
PPT
La+verdadera+amistad
PPT
How crowded is your class
PPT
OMI Shanghai workshop on Social Analytics 23 May 2011
PDF
How to get found with inbound marketing
PPTX
Netizons brand
PDF
Boletin bibliografico
PPT
2011 06 example presentation
PDF
Asistencia anual 2014
Intro to tsql unit 3
Ppt test
論文紹介 - EARS (Earthquake Alert and Report System): a Real Time Decision Suppo...
Ls flumgilleon
Wanita atau pun isteri muslim
Mobile Cloud
Make it at your library presentation draft 6 10 13
Building Webs Better
2012.+bol.bibliograf.++2º+trimestre
Presentation 5
Holiday cocktail party wear featuring – bebe dresses
Vigo presentation 07/12/2011
La+verdadera+amistad
How crowded is your class
OMI Shanghai workshop on Social Analytics 23 May 2011
How to get found with inbound marketing
Netizons brand
Boletin bibliografico
2011 06 example presentation
Asistencia anual 2014
Ad

Similar to Git installation and configuration (20)

PPT
Git 101 - Crash Course in Version Control using Git
KEY
Let's Git this Party Started: An Introduction to Git and GitHub
PPTX
Introduction to git and githhub with practicals.pptx
PDF
The Basics of Open Source Collaboration With Git and GitHub
PPTX
Git and Github workshop GDSC MLRITM
PPTX
Git and Github
PPTX
git and github-1.pptx
PPTX
Git Basics for Software Version Management
PDF
Git for folk who like GUIs
PDF
Git hub
PPTX
Introduction to git hub
PPTX
Mini-training: Let’s Git It!
PPTX
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
PPT
Introduction to git
PPTX
Git Introductive
PPT
Introduction to Git
PPTX
Bekerja dengan git v2 materi untuk kelas RPL
PDF
Git Tutorial I
PPTX
GIT.pptx
PPTX
Techoalien git
Git 101 - Crash Course in Version Control using Git
Let's Git this Party Started: An Introduction to Git and GitHub
Introduction to git and githhub with practicals.pptx
The Basics of Open Source Collaboration With Git and GitHub
Git and Github workshop GDSC MLRITM
Git and Github
git and github-1.pptx
Git Basics for Software Version Management
Git for folk who like GUIs
Git hub
Introduction to git hub
Mini-training: Let’s Git It!
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Introduction to git
Git Introductive
Introduction to Git
Bekerja dengan git v2 materi untuk kelas RPL
Git Tutorial I
GIT.pptx
Techoalien git

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Git installation and configuration

  • 1. GIT Crash Course in Version Control using Git Compiled from various internet sources by Kishor Kumar
  • 2. Git • What You Will Learn Today • What a VCS is • Why using a VCS is a good idea • Why Git is becoming, if not already, the standard VCS of choice for developers worldwide • Why you should care • Git basics, including: • How to obtain & install git • How to use it for basic, common operations • Where to go for more information
  • 3. Git • What is a Version Control System (VCS)? • A way to keep track of changes to files (& folders) • Between multiple authors (developers) • A record of who did what, when • Why is provided by commit messages! • Non-distributed (Subversion, CVS) • Server has the master repo, all commits go to the server • Distributed (Git, Mercurial) • Server has the master repo, but you have a copy (clone) of the repo on your machine • CVS, Visual Source Safe, Perforce are some others
  • 4. Git • Git is (a VCS that is)... • An open source VCS designed for speed and efficiency • Better than competing tools • Created by Linus Torvalds (for managing Linux kernel) • Your best insurance policy against: • Accidental mistakes like deleting work • Remembering what you changed, when, why • Your hard drive blowing up*
  • 5. Git • Git is (a VCS that is)... • Your best insurance policy against: • Accidental mistakes like deleting work • Remembering what you changed, when, why • Your hard drive blowing up* • The version control solution I recommend to manage code of all types • Hosted solutions include Github.com (more widespread, more expensive) or Bitbucket.com (cheaper, integrates with Jira) • or running your own Git server
  • 6. Git • Getting Git • Download the software - it's free • http://git-scm.com/downloads • or on Mac (homebrew), $ brew install git • Download a GUI, optional • http://git-scm.com/downloads/guis • Read the manual and/or the book • http://git-scm.com/docs • http://git-scm.com/book
  • 7. Git • How does Git compare? • An open source, distributed version control software designed for speed and efficiency • Unlike Subversion, Git is distributed. • This means that you can use Git on your local machine without being connected to the internet. • Revisions (commits) you make to your local repository are available to you only • The next time you connect to the internet, push your changes to a remote repository to share them & back them up offsite & off your computer
  • 8. Git • How does Git compare? • The distributed nature of Git makes it insanely fast, because most things you do happen on your local machine • The local nature of Git makes it effortless to create branches to isolate your work • The local nature of Git makes it possible to coalesce a series of changes (local commits) into a single commit on the remote branch
  • 9. Git • Understanding Git Workflow • Obtain a repository • Either via git init, or git clone, or if you already have the repo, pull changes! • Make some edits • Use your favorite text editor or source code IDE • Most IDEs have Git integration, including NetBeans • git tracks changes to binary files too: images, pdf, etc. • Less useful though, than text-based files • Stage your changes • using git add • Commit your work • git commit -m "Always write clear commit messages!" • Push to remote • git push remotename localbranch:remotebranch
  • 10. Understanding Git Remote Repo Working Directory Index Repository "Staging" "a copy of your project" git add git commit git push / git pull internet your pc "your clone of the remote repo" your edits git clone
  • 11. Git • First Steps: Check installation • Check if Git is installed: • $ git --version • git version 1.7.10.2 (Apple Git-33) • If not, brew install git or download the installer • Set your Git username and email to your global config: • $ git config --global user.name "Geoff Hoffman" • $ git config --global user.email "phpguru@salientdigital.com"* • How to enter your username and password only once: • https://help.github.com/articles/generating-ssh-keys http://git-scm.com/docs/git-config
  • 12. Git • First Steps: Obtaining a repository • Creating a repository (if one does not exist remotely): • $ git init • @see http://git-scm.com/docs/git-init • Or, cloning a remote repository: • $ git clone https://reposite.tld/account/repo.git localdir • $ git clone https://github.com/phpguru/phpredis.git • localdir is optional. The repo name is used in this case. • @see http://git-scm.com/docs/git-clone • $ cd phpredis • $ ls –la • Inspect the repo configuration: • $ vim .git/config
  • 13. Git • First Steps: Inspecting your repo • Change Directory into the repository & issue a git status • $ cd path/to/repo • $ git status • @see http://git-scm.com/docs/git-status • "Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git (and are not ignored by gitignore(5))" • @see http://git-scm.com/docs/gitignore • In other words, shows what you added, modified or deleted since your last commit.
  • 14. Git • First Steps: Inspecting your repo • Change Directory into the repository & issue a git log • $ cd path/to/repo • $ git log • $ git log --pretty=oneline • $ git log -1 • @see http://git-scm.com/docs/git-log • "Shows the commit logs." • In other words, why you committed something • Hopefully you wrote descriptive commit messages in the past!
  • 15. Git • First Steps: Making Edits & Committing • You can use whatever program you normally use to edit files. • Make a new file - newfile.txt • Edit the file as desired • Save it in your working directory • $ git status • will show the file as "Changes not staged for commit" • $ git add newfile.txt • $ git status • will show newfile.txt as "Changes to be committed" • git commit -m "Added newfile.txt as an example" • [Master 1e77a20] Added newfile.txt as an example • 1 file changed, 0 insertions(+), 0 deletions(-)
  • 16. Git • First Steps: Adding (staging) changes • Change Directory into the repository & issue a git status, then add new/modified files • $ cd path/to/repo • $ git add (file) • $ git add –A • @see http://git-scm.com/docs/git-add • "This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit." • In other words, stage your added, modified or deleted files for committing.
  • 17. Git • First Steps: Committing (staged) changes • Change Directory into the repository & issue a git status, then add new/modified files, then commit them to your local repository • $ cd path/to/repo • $ git add (file) • $ git commit -m "What did you change? Log messages matter." • @see http://git-scm.com/docs/git-commit • "Stores the current contents of the index in a new commit along with a log message from the user describing the changes." • In other words, store the added, modified or deleted files you staged in your repository.
  • 18. Git 101 Git workflow visualization Standard Workflow edits git add git add git add edits edits git commit git commit git commit Repo Work Stage Repo Work Stage Repo Work Stage Repo --> time --> Origin git clone git pull Origin git push (git init) internet your pc
  • 19. Git • First Steps: Pushing • At this point, none of those changes you've made have left your computer. (You still have local "infinite undo".) Let's push those changes to the remote repo. • git push <repository> <refspec> • git push origin master • git push origin master:master • You now have an annotated, offsite backup of the work you performed! • REMEMBER: • If you never commit, you have no history. • If you never push, you have no offsite backup. • As a rule of thumb, commit every hour, push every day. • There is no reason not to commit after every "logical stopping- point" and push when a good section of work is complete, unit tests pass, etc. • After you commit, your colleagues can pull changes down from the origin repository to their local working repository.
  • 20. Git • First Steps: Pushing your changes offsite (local -> remote) • Change Directory into the repository & issue a git push • $ cd path/to/repo • $ git push origin master • @see http://git-scm.com/docs/git-push • "Updates remote refs using local refs, while sending objects necessary to complete the given refs." • In other words, send your local changes back to the remote repo you cloned from.
  • 21. Git • First Steps: Pulling someone else's changes (remote -> local) • Change Directory into the repository & issue a git pull • $ cd path/to/repo • $ git pull origin master • @see http://git-scm.com/docs/git-pull • "Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD." • In other words, retrieve changes made to the remote repo and merge them into your local repo, updating your working copy to match.
  • 22. Git Next Steps: Working smart(er) Branch Workflow git branch "Branch" git checkout Branch git checkout Master git merge Branch edits git add git add git add edits edits git commit git commit git commit Master Branch Work Stage Branch Work Stage Branch Work Stage Master Branch --> time --> Origin git clone git pull Origin git push internet your pc
  • 23. Git 101 • Final Steps: Deploying Code • Change Directory into the repository, list the current tags, check the branch you're on, and tag the current branch/revision • $ cd path/to/repo • $ git tag –l • $ git branch • $ git tag -a v1.1 -m "Tagging version 1.1 with featurename" • @see http://git-scm.com/docs/git-tag • @see http://git-scm.com/book/en/Git-Basics-Tagging • "Add a tag reference in refs/tags/, unless -d/-l/-v is given to delete, list or verify tags. Unless -f is given, the named tag must not yet exist. If one of -a, -s, or -u <key-id> is passed, the command creates a tag object, and requires a tag message." • In other words, create a named/numbered reference to a specific revision of the code, or list prior tags created
  • 24. Git 101 • Final Steps: Deploying Code • A tag is a special type of commit... as such, just like any other commit, the tag only exists locally. The final step in tagging is to push the tag to the remote repository, just like we do with regular commits. • $ cd path/to/repo • $ git push origin v1.1 • $ git push origin --tags • @see http://git-scm.com/book/en/Git-Basics-Tagging • "By default, the git push command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them." • In other words, don't forget to push after tagging, otherwise the tag only exists on your local machine.
  • 25. Git 101 • Wrap Up: Review • The most common commands you will use during a normal day/week working with Git to manage versions of code: Download/Create a local repo $ git clone $ git init Checking what's changed $ git status $ git log Storing edits $ git add $ git commit Updating your local repo $ git pull (git fetch) $ git branch $ git merge Storing changes offsite/offbox $ git commit $ git push Storing changes offsite/offbox $ git tag $ git push