Skip to content

Instantly share code, notes, and snippets.

@thecodingaviator
Forked from cmccormack/0-fork_and_clone.md
Created March 27, 2019 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodingaviator/db4c142a6f21d1c1a19d53fc7c11d5c5 to your computer and use it in GitHub Desktop.
Save thecodingaviator/db4c142a6f21d1c1a19d53fc7c11d5c5 to your computer and use it in GitHub Desktop.
Updating a PR branch with upstream

Fork and Clone the freeCodeCamp Repository

Fork the freeCodeCamp repository

  1. Go to the freeCodeCamp repository on GitHub: https://github.com/freeCodeCamp/freeCodeCamp
  2. Click the "Fork" Button in the upper right hand corner of the interface.
  3. After the repository has been forked, you will be taken to your copy of the freeCodeCamp at https://github.com/YOUR_USER_NAME/freeCodeCamp

Clone your fork locally

  1. Go to your projects directory (e.g. ~/projects/)
  2. Run the following command to clone locally:
    • Clone into default directory freeCodeCamp (e.g. ~/projects/freeCodeCamp):
      • git clone https://github.com/YOUR_USER_NAME/freeCodeCamp.git
    • Clone into custom directory DIRNAME (e.g. ~/projects/DIRNAME)
      • git clone https://github.com/YOUR_USER_NAME/freeCodeCamp.git DIRNAME
  3. Enter project directory
    • cd freeCodeCamp OR cd DIRNAME

Set upstream repository to freeCodeCamp/freeCodeCamp

  1. Added upstream as to your remote repositories:
    • git remote add upstream https://github.com/freeCodeCamp/freeCodeCamp.git
  2. Validate upstream was added properly:
    • git remote -v should output something like
    origin    https://github.com/YOUR_USER_NAME/freeCodeCamp.git (fetch)
    origin    https://github.com/YOUR_USER_NAME/freeCodeCamp.git (push)
    upstream    https://github.com/freeCodeCamp/freeCodeCamp.git (fetch)
    upstream    https://github.com/freeCodeCamp/freeCodeCamp.git (push)

Fix Merge Conflicts for Pull Request

Update the local copy of the upstream remote

  • git fetch upstream

Optionally download and install Github Hub

  • Github Hub
  • Greatly simplifies many of the git commands, especially useful when working with Pull Requests.

Switch to the PR branch (using git OR hub):

git

  • git fetch upstream refs/pull/PULLREQ_NUMBER/head:pr-PULLREQ_NUMBER
  • git checkout pr-PULLREQ_NUMBER

hub

  • hub checkout https://github.com/freeCodeCamp/freeCodeCamp/pull/PULLREQ_NUMBER

Rebase commits on top of upstream/master

  • git rebase upstream/master OR
  • git pull --rebase upstream master

Resolve commits, add your own commits, etc...

  • If there is a conflict and it has been resolved:
    • git add [filename]
    • git rebase --continue
  • If you get a message stating there are no changes you may need to use git rebase --skip
  • You do NOT need to add a merge commit when rebasing

(Optionally) squash commits

  • git rebase -i upstream/master
  • Editor should open allowing you to choose which commits to squash
    • Add pick before the commit you want to keep
    • Add squash before any commit you want to squash into the pick commit
    • Save and exit
  • Editor should open allowing you to choose which commit messages to keep
    • Delete any superfluous commit messages
    • Save and exit

Write commits to users PR branch (using git OR hub):

git

  • git push git@github.com:USERNAME/REPONAME.git pr-PULLREQ_NUMBER:THEIR_BRANCH_NAME (may require -f flag)

hub

  • hub push (may require -f flag)

Useful Aliases

Alias Purpose Shell Syntax
gcm Checkout master branch alias gcm="git checkout master"
gb Show current branches alias gb="git branch"
gf Fetch from remote repository alias gf="git fetch"
gfu Fetch from upstream remote repository alias gfu="git fetch upstream"
grb Rebase onto a provided branch alias grb="git rebase"
grbc Continue rebase after making changes alias grbc="git rebase --continue"
grbs Skip current conflict alias grbs="git rebase --skip"
grba Abort current rebase alias grba="git rebase --abort"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment