Skip to content

Instantly share code, notes, and snippets.

@ctesta01
Last active March 23, 2022 19:35
Show Gist options
  • Save ctesta01/08f201469e88c94308c0b7bfab9869a7 to your computer and use it in GitHub Desktop.
Save ctesta01/08f201469e88c94308c0b7bfab9869a7 to your computer and use it in GitHub Desktop.
Notes on using Git and GitHub with Pull Requests

Using Feature Branches and Pull Requests on GitHub

The following instructions walk through cloning a repository, creating a feature branch, and submitting a pull request.

You'll need to be ready to use git1 to follow along, and I suggest setting up ssh-key based authentication2 so you don't have to enter your username and password every time you are transferring code to and from GitHub.

Instructions

# clone your repository
git clone git@github.com:repositoryName.git 

# move into directory 
cd repositoryName

# create a new branch 
git checkout -b new-feature

# push new branch to origin (origin refers to GitHub in this instance)
git push origin new-feature 

# make edits 
# ... 

# add work to the staging area for your next commit 
git add file1.txt file2.png # etc

# write commit message 
git commit -m "commit message here" 

# push to origin 
git push 

# continue to make edits until the changes are ready to merge with main 
# ... 

# once ready for merging with main, pull any changes from main that may have occurred in the interim 
git pull origin main 

If there are conflicts, resolve and commit the merge, and push it to GitHub (e.g. "origin").

Open GitHub (e.g. github.com/repositoryName) and create a pull request when doing so, you can assign it to a team member to merge into main

submitting a pull request

Spot-checking is done at this point to make sure errors aren't introduced to the software.

If there's more to do before the new feature branch can be merged into main, we can put comments detailing the situation in the pull request as well as make additional commits to the new feature branch.

Once the commits of the new feature branch have been merged into main, the new feature branch should be deleted to keep the number of active branches to a minimum. There is a button on GitHub that appears after merging a branch, prompting you to delete it.

GitHub button prompting user to delete old feature branches

If you or other developers on your team use the Delete branch button on GitHub, you should use git fetch -p to prune the branches on your local machine to match what is on origin.

Two more useful things: if you want to delete a branch on your local computer, you can do that with git branch -d branch-name or with -D. If you want to rename a branch, that is done with git branch -m old-name new-name.

Here are some relevant references on git and GitHub:

Footnotes

  1. https://www.codecademy.com/article/git-setup

  2. https://jdblischak.github.io/2014-09-18-chicago/novice/git/05-sshkeys.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment