and git-flow


What is git?


git is a distributed source control system, with an emphasis on speed.


Forget everything you know about source control



Source Control Basics


repository = the place where your code is stored


working directory = the place, on your machine, in which you are editing the code


untracked file = a file which is not yet under any source control system


vs


TFS is centralised


you check your changes into a central repository


git is distributed


you commit your changes to a local copy of the repository

when you are ready to share your changes, you push your changes to the central repository


What does this mean?


You can commit your code, as often as you like - without affecting anyone else.


You can view your local changes, and move around or even discard your local code.

 

-     commit
check in     push
get latest     fetch
merge     merge
get latest + merge   
  pull
-   
  clone

git clone


The  git clone  command creates a copy of an existing Git repository.


Cloning is the most common way for developers to obtain a working copy of a central repository.



git add


The  git add  command adds the untracked files you have changed in your working directory to the next commit.



git commit


The  git commit  command takes the changes which were staged by  git add  and commits them to your local repository.



git push


The  git push  command is how you transfer commits from your local repository to a remote repository.



example



cheat sheet
clone an existing repository
git clone git@apap-github.rfs.nsw.gov.au:GitHubTraining/MyFirstRepository.git
add your files
git add 'filename.txt'  // Adds the specific filegit add .               // Adds all files not being trackedgit add '*.txt'         // Adds all files which match the expression
commit your changes
git commit -m 'Commit message here' 
check what's in this commit
git status 
send the changes back to the server
git push origin master 

Branching


git is very efficient at branching


Branching


Branches are a safereliable way to work on multiple versions of a project within a single repository.

Branching


Branching is a great way to ensure that any changes you make to the code in a repository are made in isolation to any other changes.


For example:


  • New Features
  • Bug fixes

git branch


The  git branch  command lets you create, list, rename, and delete branches.


It doesn’t let you switch between branches.

git checkout


The  git checkout  command lets you navigate between the branches created by  git branch .


Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.

example


create a new branch called 'icon-toban-ui'

git branch "icon-toban-ui" 

switch your working directory to that branch

git checkout "icon-toban-ui" 

add a file called "index.html" and commit your changes

git add "index.html"
git commit -m "Added an index page" 

switch back to your master branch

git checkout master 

index.html is not on the master branch

Merging


Merging is git's way of putting 2 branch histories back together again.


git merge


The  git merge  command lets you take the branches and integrate them into a single branch.

example


make sure we are on the branch 'master'

git checkout master 

merge the changes from 'icon-toban-ui' into 'master'

git merge 'icon-toban-ui' 

index.html file is now in master

Fetching


Fetching is git's way of bringing any commits down from the remote repository so that they can be reviewed on your local machine.


The commits are not applied to your working directory.

git fetch


The  git fetch  command imports commits from a remote repository into your local repo.


It does not perform a merge on the code.

git pull


The  git pull  command imports commits from a remote repository into your local repository, and merges the changes into your current working directory.


It is the same as running:


 git fetch origin git merge


5 minute break

What is GitHub?


GitHub is a web-based hosting service for projects

that use git as their revision control system.



GitHub features


git repository hosting

issue tracker

wiki


code review


example


Issue management



http://bit.ly/LuI1yV

example


Wiki


Knowledge base

Release notes

Meeting minutes


etc... ideas?

Code review


GitHub supports code review through pull requests


but... first, let's talk workflow

What is git-flow?


git-flow is a branching model for git, which is suited to collaboration and scaling the development team.



What is git-flow


The git-flow Workflow defines a strict branching model designed around the project release.



Branches


git-flow repositories consist of a number of branches which aid development.

develop   contains the development code
branched from master

feature contains code for a specific feature
branched from develop

release contains code which is to be in the next release
branched from develop, merged into master

hotfix contains hot-fixes for an existing release
branched from master, merged into master, release and develop

master the current production release
changes from release and hotfix are merged into this

Advantages


Features can be developed in parallel.

Features can be deployed in isolation.


master is always releasable.


hotfixes are merged back into all branches.

whiteboard example


git-flow helpers


Instead of typing all of the  git *  commands to use git-flow, we will use the git-flow helpers developed by @nvie


git-flow cheat-sheet:

http://bit.ly/1fpEHPR

example


create the new feature in the repository

git flow feature start myfeature 

make your changes to the feature using standard commands


publish the feature so that others can work on it

git flow feature publish myfeature 


others can then get the feature by running

git flow feature pull myfeature 

and commit & push their changes using standard commands

git add .
git commit -m "My message"
git flow publish feature myfeature 


Pulling it all together


In this example, we will walk through an entire scenario of:

  1. Creating a repository in GitHub.
    1. Adding a feature issue in the tracker.
  2. Cloning the repository and initialising git-flow.
  3. Adding and publishing a feature.
  4. Pull request for someone to review the code.
  5. Finishing a feature.


Next steps


  • Another training session.
    • Hands on?
    • Self-driven?
    • Class-room?
  • Manual / tutorial / walk-through.
  • What else?..


Practice makes perfect.


questions?

Copy of Git, GitHub & GitFlow

By Fabio Nowaki

Copy of Git, GitHub & GitFlow

  • 1,827