Git Flow
A Recommended Workflow for Teams
Setting up the repository
- Initialize a new Git repository (repo) and make initial file structure on your local machine
- Make initial commit (
git add [file-name]
,git commit -m 'Initial commit'
) - Create a new repository on GitHub
- Link your local and GitHub repository (add remote)
- Push structure to remote repository (push to the main branch)
- Add all team members as collaborators
- All team members should clone the repo to their local machines (don’t fork!)
General Workflow:
- Start on main branch
git checkout main
)
- Checkout to a feature branch
git checkout -b [feature/branch-name]
- Do work
- Commit frequently
git status
git diff
git add [file-name]
git commit -m '[Message]'
)- Repeat until feature is complete
- Before pushing your branch, make sure you’re up to date with the remote main branch
git checkout main
git pull origin main
git checkout [feature-branch-name]
git merge main
- If needed, fix merge conflicts (tells you on command line where to look in editor)
- Important! Run your code (open up your app) and ensure that everything is working as expected
- Once you are confident with your code, push it up to the remote repo
git push origin [feature-branch-name]
- Go to GitHub in your browser
- Create a pull request
- Write an informational comment
- Add all necessary team members as reviewers
- Once you are confident with your PR, hit the ‘Submit Pull Request’ button
- Contact partner to review pull request
- Partner reviews code, adds comments, and merges pull request
- Or, you can ‘Request Changes’ and wait for you partner to push up new code before merging
- Once the new code is merged into the remote main branch, all team members should pull down the changes to their own main branches
git checkout main
git pull origin main
- If you are currently working on a branch and want to continue on that branch, then run:
git checkout [feature-branch-name]
git merge main
- Keep coding on that branch.
- If you are ready to add a new feature:
- Start back at step 1!
Short and Sweet Version:
- Make sure your main branch is updated with the remote main branch
- Checkout to a branch when coding
- Push up your branch when it’s complete
- Partner merges your branch into main
- Repeat
Advanced: Want a more thorough code review?
When your teammate asks for a code review, you can review the code in GH, but that makes it hard to actually run and test the code. To get the code to your local machine, go through these steps:
- After the PR is opened by your partner, run
git fetch
on your machine. This will give you access to all of the remote branches. - Run
git checkout [name-of-partner's-branch]
and you should now have the code from the branch that your partner is trying to merge into main - Test the code locally (open the app, look through code)
- Then leave the code review in GH as normal!