In this example application, you will be practicing git workflow as a team.
Objectives
- Describe the forking workflow in git
- Describe what rebase does
- Setup diff and merge tools
- Handle a merge with conflicts
There are many different workflows for using git as a team. We are going to focus on the forking workflow which is common for open source projects.
The forking workflow is described below:
- Create an organization with an official repository for the project
- All contributors to the project should fork the repo to their own github account and then clone it locally
- All changes for the project will be done in your personal reposity (likely in a feature branch) and then merged into the offical repository via a pull request.
- The pull request is reviewed by someone else on the team, approved, then merged. Note that approval means looking over the quality of the code and making sure there are no merge conflicts
EXERCISE
For more details read this atlasian article on git workflows.
Rebasing is a powerful tool in git that must be understood and used correctly. A rebase essentially changes the commit history. It should only be done to commits that have not be checked in publically yet.
A common use case for a rebase is described in this atlasian article on rebase.
It is often useful to see the changes to your code visually. With xcode installed, you should have a tool installed in the terminal called opendiff
. If you prefer another tool, check out this article.
To tell git to use opendiff, open the .gitconfig
file in your home directory. Add the following to .gitconfig
:
[merge]
tool = opendiff
[diff]
tool = opendiff
[difftool]
prompt = false
To use the tool, run git mergetool
or git difftool
. You can modify the .gitconfig
file to add an alias. For example:
[alias]
dt = difftool
Now you can run git dt
for git difftool
.
Here are some other useful alias':
[alias]
lol = log --graph --decorate --pretty=short --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
last = log -1 HEAD
co = checkout
br = branch
ci = commit
st = status
unstage = reset HEAD --
dt = difftool
mt = mergetool
To understand fixing merge conflicts, you have to learn by doing. As a group of at least 2 or 3 people:
- Create an organization in github.
- Fork this repo into your organization.
- Pretend that your new fork is now your official repo for the project
- All members should then fork the repo into their personal github accounts
- Clone,
npm install
,knex migrate:latest
and make sure the app is running. - Now make some commits! In
home.jade
, add some information about the puppy rescue shelter. Each person should add different info:- When the shelter was founded
- What you should do if you found a puppy that needs rescuing
- How to adopt a puppy
- Contact info
- etc
- We want to keep all of the info on the page, so any merge should try to perserve all info
- Perform pull requests following the forking workflow.