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
TFS is centralised
you check your changes into a central repository
git is distributed
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.
get latest + merge
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.
The git add command adds the untracked files you have changed in your working directory to the next commit.
The git commit command takes the changes which were staged by git add and commits them to your local repository.
The git push command is how you transfer commits from your local repository to a remote repository.
add your files
git clone firstname.lastname@example.org:GitHubTraining/MyFirstRepository.git
commit your changes
git add 'filename.txt' // Adds the specific file
git add . // Adds all files not being tracked
git add '*.txt' // Adds all files which match the expression
git commit -m 'Commit message here'
git push origin master
git is very efficient at branching
Branches are a safe, reliable way to work on multiple versions of a project within a single repository.
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.
The git branch command lets you create, list, rename, and delete branches.
It doesn’t let you switch between branches.
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.
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 is git's way of putting 2 branch histories back together again.
The git merge command lets you take the branches and integrate them into a single branch.
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 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.
The git fetch command imports commits from a remote repository into your local repo.
It does not perform a merge on the code.
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
5 minute break
What is GitHub?
GitHub is a web-based hosting service for projects
that use git as their revision control system.
git repository hosting
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.
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
Features can be developed in parallel.
Features can be deployed in isolation.
master is always releasable.
hotfixes are merged back into all branches.
Instead of typing all of the git * commands to use git-flow, we will use the git-flow helpers developed by @nvie
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:
- Creating a repository in GitHub.
- Adding a feature issue in the tracker.
- Cloning the repository and initialising git-flow.
- Adding and publishing a feature.
- Pull request for someone to review the code.
- Finishing a feature.
- Another training session.
- Hands on?
- Manual / tutorial / walk-through.
- What else?..
Copy of Git, GitHub & GitFlow
By Fabio Nowaki