Git Collaborative Workflow

Learning Goals

Creating a New Repo

Oftentimes, we start a project by forking or cloning a pre-existing repository from GitHub. Today we are going to start from scratch and build our own! You’ll be working with a partner to run through the process of creating a new repo, adding some code, submitting pull requests, resolving merge conflicts and more!

Partner One

Pick one person to create the repo. The other person should be watching and advising!

Command Line (Terminal)

  • Use the command line to make a new directory called “git-collaboration-practice”
  • Add a README.md file to your directory
  • Open up your directory in your text editor and add some text to that README
  • Initialize git by running git init
  • Stage your README by running git add README.md
  • Make your first commit by running git commit -m "Initial Commit"

GitHub Time!!

  • Click the plus to create a New Repository. Add Repository name (should match your local directory name). Click Create Repository.
  • Run the steps of “…or push an existing repository from the command line”
  • Invite your partner to collaborate (find this on the repo page under settings, manage access, invite a collaborator)

Replacing master with main

Historically, the default branch on GitHub has been named master. This is something you most likely will still come across, but we (and others) have switched to main to promote more inclusivity in tech.

Read more about this important change here!

To make your local machine’s git default to branch main, you’ll first need to update to the latest version of git. Follow these steps to do that.

Then you have to tell git what the default branch should be. You can run this command in your terminal to do that:

git config --global init.defaultBranch main

Cloning the Repo

Partner Two

Getting Started

  • Get the link to your partner’s Github repo
  • Accept the collaborator invitation (you’ll probably get an email)
  • Clone it down to your machine
    • Do NOT fork; clone your partner’s repo!!

Command Line & Text Editor

  • Create a new branch (what name makes the most sense here?)
  • Open up the repo in your text editor and add some text to that README
  • Add, commit and push that code to your branch

GitHub

  • Create a pull request to merge your branch into main (DONT MERGE IT YET)
  • Add your partner as a reviewer

How to Write a Good Commit Message

Begin the commit message with the type of the commit followed by a : and brief description.

Types of commits include:

  • fix - use if committed code is fixing a bug(broken code).
  • feat - stands for feature. This will likely be your most common type that you use. It should be used for any new functionality that is committed.
  • test - use if committed code is adding test functionality.
  • refactor - use if updating and/or removing existing code.
  • docs - use if updating your readme.

Examples of good commit messages:

  • fix: Broken calculation for percent high ranking cards
  • feat: Add shuffle to deck
  • test: Add test for shuffle

Code Review

Partner One

GitHub

  • Check out your partner’s pull request on GitHub. Spend some time looking through the interface together. What information can you see about your partner’s code? How can you leave comments or request changes?
  • Why do you think its important to be able to review someone else’s code in this format?

Reviewing Code Locally

  • Checkout your partner’s branch
    • You will need to fetch existing branches first 😉
  • Look at their code in your text editor
    • In a real application, you might be opening it up in the browser, checking for errors, running tests, etc.

GitHub

  • Merge that pull request!
  • Why do you think developers shouldn’t merge their own pull requests?

Note about checking remote branches

After fetching branches, note that git branch will still not display remote branches. In order to see remote branches, you have to run git branch -r. To see both local and remote branches, you must run git branch -a.

Continuing Work

Partner Two

  • Switch to your main branch
  • Pull down the changes that have been merged in
  • Why do you think its important to pull down changes before starting the workflow process again?

Common Questions

Can I work on the same branch as my partner?
Yes! As long as a branch is pushed up to GitHub, anyone can pull it down and work on it. This is a common place for conflicts to arise though, so make sure you are communicating well and often. Sticking to different parts of the codebase is better practice to avoid merge conflicts for now.

When should I commit?

  • Early and often!
  • When you’ve completed one task or fix
  • You’re done for the day or reached a stopping point.
  • If you have code you want someone else to see

What is an atomic commit?

  • An “atomic” change revolves around one task or one fix.
  • Atomic means it could not be smaller

When should I submit a pull request?

  • When you’ve created a new, fully functional feature
  • When you have successfully solved a bug or fixed something broken

Lesson Search Results

Showing top 10 results