Git Workflow
A guide for programming within version control.
Create a Repo
To create a repo, you can start either locally or on GitHub. If you already have
files you've created, you might want to start locally. Otherwise, it's nice to
start on GitHub because it allows you to easily add a .gitignore
, a
README.md
, and a license.
Starting a new repo locally
- Make sure that your present working directory (
pwd
) is the project directory where you want to work on your files. $ git init .
. This will create a repository in the current directory.$ hub create <project-name>
. This will create a repository on GitHub with the name you specify. E.g.$ hub create 1.0-My-Project
.- Create a README.md (it can be empty, or just have the name of the project) in your text editor.
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master
Starting a new repo on GitHub
- Click the + > New Repository button in the GitHub interface.
- Give the repository a good name, a "Node"
.gitignore
, and an MIT license. - Copy the "SSH URL" that is on the right hand side of the repository page.
$ git clone <url>
, pasting the url you just copied to clone the repository to your computer.
Maintain a Repo
- Avoid including files in source control that are specific to your
development machine or process (e.g.
.DS_Store
). You can ignore these files with.gitignore
. - Don't work on the master branch after the initial commit, do all work in a feature branch.
- Only merge a branch into master once you have received a :+1:.
- Delete local and remote feature branches after merging.
- Rebase frequently to incorporate upstream changes.
- Use a pull request for code reviews.
Write a Feature
Create a local feature branch based off master.
git checkout master
git pull
git checkout -b <branch-name>
Prefix the branch name with your initials.
When feature is complete, stage the changes.
git add .
When you've staged the changes, commit them.
git status
git commit
Write a [good commit message]. Example format:
Present-tense summary under 50 characters
* More information about commit (under 72 characters).
* More information about commit (under 72 characters).
http://project.management-system.com/ticket/123
Share your branch.
git push origin <branch-name>
Summary
$ git checkout -b <branch-name>
- Do your work
$ git add .
$ git status
$ git commit
$ git push
or$ git push -u origin <branch-name>
Resources
- [good commit message]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html