Table of Contents

Sample Git Workflow

Sailboat, used in a post about Git Workflow.

This is the Git workflow my team used for our SWEN-261 group project at RIT: one branch per task, small commits, and a pull request to merge into main. Each step has the command and a filled-in example you can copy.

TLDR

  1. Clone the repository once.
  2. Pull main before you start.
  3. Create and push a branch for your task.
  4. Check the status, add your files, and commit.
  5. Push your branch and compare it with main.
  6. Open a pull request on GitHub.
  7. After the merge, everyone pulls main.

Git workflow diagrams

Left: Sandra Winkler – Git Workflow.
Right: Molly Nemerever – Git Workflow

Clone

git clone <project_name>
git clone https://github.com/RIT-SWEN-261-04/team-project-2215-swen-261-04-2-the-reading-room

Pull

Always pull code first!

How to pull from main:

git pull <full-url>
git pull https://github.com/RIT-SWEN-261-04/team-project-2215-swen-261-04-2-the-reading-room

🌸👋🏻 Enjoying this post? Get the next issue of [ret]2read. Once a month, I’ll email you whatever’s on my mind, usually Apple security research, offensive security, open source software freedom, and operating system internals.

Branches

Create new branch:

git checkout -b <name-of-branch>
git checkout -b olivia-login-unit-tests

Push your new unedited branch to GitHub: 

git push origin <name-of-branch>
git push origin olivia-login-unit-tests

How to switch to a branch:

git checkout <name-of-branch>
git checkout olivia-login-unit-tests

If needed for some reason, you can switch to main branch:

git checkout main

Status

Check the status of changed files:

git status

Want your company or product in front of [ret]2read readers?
One sponsor per issue â†’

Add

Add or “stage” file to be included in the next commit:

git add <changed-file-name>
git add olivia.txt

This is considered bad practice. However, you can add all of the changed files in the branch (two ways):

git add -A
git add .

Commit

Committing with a message:

git commit -m "<text>"
git commit -m "added contact information to olivia.txt"

Push

Push your commits and set your branch to track its copy on GitHub:

git push --set-upstream origin <name-of-branch>
git push --set-upstream origin olivia-login-unit-tests

Compare your branch with main before you open a pull request:

git diff main...<name-of-branch>
git diff main...olivia-login-unit-tests

Pull Requests

We opened pull requests in GitHub’s web interface:

  1. Go to https://github.com/.
  2. Navigate to the project.
  3. Click branches (image 1)
  4. Click pull request (image 2)
GitHub repository page with the branches link
Image 1: Click branches
GitHub branches page with the new pull request button
Image 2: Click pull request

Notify and Pull

Notify group members about merge. Then, have everyone pull from main.

How to pull from main:

git pull <full-url>
git pull https://github.com/RIT-SWEN-261-04/team-project-2215-swen-261-04-2-the-reading-room

Pull main branch to your branch:

git pull origin main

Resources

  • Oh Shit, Git!
    • Oh Shit, Git! If you find git confusing, don’t worry! You’re not alone. People who’ve been using it every day for years still make mistakes and aren’t sure how to fix them.
    • Git is hard: screwing up is easy, and figuring out how to fix your mistakes is fucking impossible. Git documentation has this chicken and egg problem where you can’t search for how to get yourself out of a mess, unless you already know the name of the thing you need to know about in order to fix your problem.
  • Learn Git Branching
    • Interested in learning Git? Well you’ve come to the right place! “Learn Git Branching” is the most visual and interactive way to learn Git on the web; you’ll be challenged with exciting levels, given step-by-step demonstrations of powerful features, and maybe even have a bit of fun along the way.

Conclusion

If you found this workflow helpful, check out my other articles for SWEN-261 and my offensive security cheatsheet for CSEC-202, Offensive Security Attack Phases and Frameworks.

Portrait of Olivia Gallucci in garden, used in LNP article.

Written by Olivia Gallucci

Olivia is senior security engineer, certified personal trainer, and freedom software advocate. She writes about offensive security, open source software, and professional development.

Discover more from [ret]2read

A Monthly OS Internals Publication by Olivia Gallucci. Subscribe now to keep reading and get access to the full archive.

Continue reading