Skip to content

Git Workflow

Ruipeng Li edited this page Feb 9, 2017 · 2 revisions

The content of this document was copied from "Git Workflow" by Rob Falgout

Some of this document is motivated by the GitFlow model.

Adding Non-trivial Features

Non-trivial features will be developed on a separate branch with a name of the form *-dev. Once the feature is finished, tested, and approved, it will be merged back into the master branch and the development branch will be deleted. Here is an example workflow for feature "foo":

Clone evsl into directory evsl-foo-dev and change to that directory.

git clone <-repo> evsl-foo-dev
cd evsl-foo-dev

Create new branch foo-dev (if not already present) and change to that branch.

git branch foo-dev
git checkout foo-dev

If co-developing the feature with others, create a shared remote branch and make sure that push/pull track the remote branch (the -u option).

git push -u origin foo-dev

Develop code.

git status # See the status of code changes in the branch
git add <files> # Stage files to be commited to the branch
git commit # Commit changes
...
git push # Push changes to the remote branch to share with co-developers
...
git pull # Pull co-developer changes from remote branch
...

Test the code. It may be useful to merge the master branch into the feature branch at this point, especially if lots of changes were also made on master. Use the --no-ff option any time a merge of two different branches is done, because it produces better branching visualization and history.

git checkout master # Change to the master branch
git pull # Pull in any new changes made to the master branch
git checkout foo-dev # Change back to the foo-dev branch
git merge --no-ff master # Merge master into the foo-dev branch

Create a pull request to finalize changes before merging into the master branch.

Merge the feature into the master branch.

git checkout master # Change to the master branch
git pull # Pull in any new changes made to the master branch
git merge --no-ff foo-dev # Merge foo-dev into the master branch

Delete the feature branch both locally and remotely.

git branch -d foo-dev
git push origin --delete foo-dev

Useful Git Commands and Information

See a list of local and remote branches and which is the current branch.

git branch --all

See the commit log in a graphical format showing the branch history.

git log --graph --oneline --decorate --all

Other useful ways to visualize branch history, commit diffs,

  • Gitk - Use locally on the command line (i.e., 'gitk' or 'gitk --all'). Consider setting up (and saving) a custom view with 'View -> New view' that shows "All refs" at a minimum.
    

Writing Effective Git Commit Logs

When entering commit log information, type in a short descriptive title line following by a blank line then any additional information that may be useful. Git will use the title line in commands like git log --graph --oneline above. More discussion on how to write an effective git log message can be found here.

Clone this wiki locally