Git Workflow
Gary
2014/11/10
Outline
• What is Git?
• Git Workflow and Git Commands
• Branching and merging
• Git Implement
What is Git?
• Git is a distributed revision control and source code management
(SCM) system with an emphasis on speed, data integrity, and support
for distributed, nonlinear workflows.
• Git was initially designed and developed by Linus Torvalds for Linux
kernel development in 2005, and has since become the most widely
adopted version control system for software development.
Git Design Goals
• Speed
• Simple design
• Strong support for thousands of parallel branches
• Fully distributed
• full local repository
• offline commits
• full size repository
• Able to handle large projects like Linux kernel effectively
• Ensure integrity
Distributed Development
• Every Git working directory contains the complete repository, history
and full revision tracking capabilities
• You’re not dependent on a central server and you don’t have to be
online
• Git is extremely fast - much faster than SVN, CVS and other systems
• Revisions (commits) you make to your local repository are available to
you only
Distributed Development
• The next time you connect to the internet, push your changes to a
remote repository to share them and back them up
• 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
Tracking Changes (most VCS)
Tracking Changes (the Git way)
File Status Lifecycle
Understanding of Workflow
• Obtain a repository
• git init or git clone
• Make some changes
• Stage your changes
• git add
• Commit changes to the local repository
• git commit –m “My message”
• Push changes to remote
• git push remotename remotebranch
Git Commands
• Setup and Config
• git config
• Get and set repository or global options
• git help
• Display help information about Git
• Getting and Creating Projects
• git init
• Create an empty Git repository or reinitialize an existing one
• git clone
• Clone a repository into a new directory
Git Commands
• Basic Snapshotting
• git add
• Add file contents to the index
• git status
• Show the working tree status
• git commit
• Record changes to the repository
Git Commands
• Branching and Merging
• git branch
• List, create, or delete branches
• git checkout
• Checkout a branch or paths to the working tree
• git merge
• Join two or more development histories together
Git Commands
• Sharing and Updating Projects
• git fetch
• Download objects and refs from another repository
• git pull
• Fetch from and integrate with another repository or a local branch
• git push
• Updating remote refs along associated objects
Branching and Merging
• Example
1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
Branching and Merging
• Example
1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
iss53
git checkout –b iss53
Or
git branch iss53
git checkout iss53
Branching and Merging
• Example
1. Develop a website
2. To implement a new function, create a new branch
3. Work on this new branch
C0 C1 C2
master
iss53
C3git commit –a –m ‘add a new footer’
Branching and Merging
• There is a bug on the system
1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
master
iss53
C3
Branching and Merging
• There is a bug on the system
1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
master
iss53
C4
git checkout –b hotfix
git commit –a –m ‘fixed the problem’
hotfix
C3
Branching and Merging
• There is a bug on the system
1. Go to stable released version
2. Create a new branch, and debug
3. After solving the problem, merge the branch
4. Back to the new function branch
C0 C1 C2
iss53
C4
git checkout master
git merge hotfix
hotfix
C3
master
Branching and Merging
• After implement the new function, merge into stable version
C0 C1 C2
iss53
C4
git branch –d hotfix
git checkout iss53
git commit –a –m ‘finish the new footer ’
C3
master
C5
Branching and Merging
• After implement the new function, merge into stable version
C0 C1 C2
iss53
C4
git checkout master
git merge iss53
C3
master
C5
C6
Git Implement
• Environment
• Windows 7 64-bit
• Git-1.8.4
• Step 1 : Setting user information
• Use git bash
git config --global user.name “custom user name"
git config --global email “custom e-mail"
Git Implement
• Step 2 : Initialize
• Use git init here
• Or use git bash and key in git init
Git Implement
• Step 3 : Add files
• In git bash, key in
• Step 4 : Version control
git add .
git add *
git commit –a
or
git commit -m “the information"
Git Implement
• Step 5 : Start Using
git add -u
Q&A Goodbye!

Git Workflow

  • 1.
  • 2.
    Outline • What isGit? • Git Workflow and Git Commands • Branching and merging • Git Implement
  • 3.
    What is Git? •Git is a distributed revision control and source code management (SCM) system with an emphasis on speed, data integrity, and support for distributed, nonlinear workflows. • Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005, and has since become the most widely adopted version control system for software development.
  • 4.
    Git Design Goals •Speed • Simple design • Strong support for thousands of parallel branches • Fully distributed • full local repository • offline commits • full size repository • Able to handle large projects like Linux kernel effectively • Ensure integrity
  • 5.
    Distributed Development • EveryGit working directory contains the complete repository, history and full revision tracking capabilities • You’re not dependent on a central server and you don’t have to be online • Git is extremely fast - much faster than SVN, CVS and other systems • Revisions (commits) you make to your local repository are available to you only
  • 6.
    Distributed Development • Thenext time you connect to the internet, push your changes to a remote repository to share them and back them up • 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
  • 7.
  • 8.
  • 9.
  • 10.
    Understanding of Workflow •Obtain a repository • git init or git clone • Make some changes • Stage your changes • git add • Commit changes to the local repository • git commit –m “My message” • Push changes to remote • git push remotename remotebranch
  • 11.
    Git Commands • Setupand Config • git config • Get and set repository or global options • git help • Display help information about Git • Getting and Creating Projects • git init • Create an empty Git repository or reinitialize an existing one • git clone • Clone a repository into a new directory
  • 12.
    Git Commands • BasicSnapshotting • git add • Add file contents to the index • git status • Show the working tree status • git commit • Record changes to the repository
  • 13.
    Git Commands • Branchingand Merging • git branch • List, create, or delete branches • git checkout • Checkout a branch or paths to the working tree • git merge • Join two or more development histories together
  • 14.
    Git Commands • Sharingand Updating Projects • git fetch • Download objects and refs from another repository • git pull • Fetch from and integrate with another repository or a local branch • git push • Updating remote refs along associated objects
  • 15.
    Branching and Merging •Example 1. Develop a website 2. To implement a new function, create a new branch 3. Work on this new branch C0 C1 C2 master
  • 16.
    Branching and Merging •Example 1. Develop a website 2. To implement a new function, create a new branch 3. Work on this new branch C0 C1 C2 master iss53 git checkout –b iss53 Or git branch iss53 git checkout iss53
  • 17.
    Branching and Merging •Example 1. Develop a website 2. To implement a new function, create a new branch 3. Work on this new branch C0 C1 C2 master iss53 C3git commit –a –m ‘add a new footer’
  • 18.
    Branching and Merging •There is a bug on the system 1. Go to stable released version 2. Create a new branch, and debug 3. After solving the problem, merge the branch 4. Back to the new function branch C0 C1 C2 master iss53 C3
  • 19.
    Branching and Merging •There is a bug on the system 1. Go to stable released version 2. Create a new branch, and debug 3. After solving the problem, merge the branch 4. Back to the new function branch C0 C1 C2 master iss53 C4 git checkout –b hotfix git commit –a –m ‘fixed the problem’ hotfix C3
  • 20.
    Branching and Merging •There is a bug on the system 1. Go to stable released version 2. Create a new branch, and debug 3. After solving the problem, merge the branch 4. Back to the new function branch C0 C1 C2 iss53 C4 git checkout master git merge hotfix hotfix C3 master
  • 21.
    Branching and Merging •After implement the new function, merge into stable version C0 C1 C2 iss53 C4 git branch –d hotfix git checkout iss53 git commit –a –m ‘finish the new footer ’ C3 master C5
  • 22.
    Branching and Merging •After implement the new function, merge into stable version C0 C1 C2 iss53 C4 git checkout master git merge iss53 C3 master C5 C6
  • 23.
    Git Implement • Environment •Windows 7 64-bit • Git-1.8.4 • Step 1 : Setting user information • Use git bash git config --global user.name “custom user name" git config --global email “custom e-mail"
  • 24.
    Git Implement • Step2 : Initialize • Use git init here • Or use git bash and key in git init
  • 25.
    Git Implement • Step3 : Add files • In git bash, key in • Step 4 : Version control git add . git add * git commit –a or git commit -m “the information"
  • 26.
    Git Implement • Step5 : Start Using git add -u
  • 27.