Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
Last active July 1, 2025 23:27
Show Gist options
  • Select an option

  • Save rgreenjr/96d182fe3c47ed6fce82 to your computer and use it in GitHub Desktop.

Select an option

Save rgreenjr/96d182fe3c47ed6fce82 to your computer and use it in GitHub Desktop.

Revisions

  1. rgreenjr revised this gist Oct 7, 2021. 1 changed file with 0 additions and 21 deletions.
    21 changes: 0 additions & 21 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -172,24 +172,3 @@ git merge upstream/master
    git checkout FEATURE_BRANCH
    git rebase master
    ```


    ## Hosting Non-Public Repos

    ```sh
    # make bare copy of repo
    cd ~/code
    git clone --bare my_project /Users/rgreen/git/my_project.git

    # clone repo locally (see below for non-local)
    cd ~/code
    git clone /Users/rgreen/git/my_project.git
    cd my_project
    git remote set-url origin /Users/rgreen/git/my_project.git

    # clone repo non-locally (see above for local)
    cd ~/code
    git clone rons-imac.local:/Users/rgreen/git/my_project.git
    cd my_project
    git remote set-url origin rons-imac.local:/Users/rgreen/git/my_project.git
    ```
  2. rgreenjr revised this gist Sep 18, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -120,6 +120,12 @@ git checkout development
    git merge --no-ff branch_name
    ```

    ```sh
    # add tag
    git tag 1.2.3
    git push origin v1.2.3
    ```

    ## Contributing to Open Source

    - [How to Rebase a Pull Request](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request)
  3. rgreenjr revised this gist Feb 27, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -185,6 +185,5 @@ git remote set-url origin /Users/rgreen/git/my_project.git
    cd ~/code
    git clone rons-imac.local:/Users/rgreen/git/my_project.git
    cd my_project
    git clone rons-imac.local:/Users/rgreen/git/my_project.git
    git remote set-url origin rons-imac.local:/Users/rgreen/git/my_project.git
    ```
  4. rgreenjr revised this gist Feb 27, 2019. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -172,15 +172,19 @@ git rebase master

    ```sh
    # make bare copy of repo
    git clone --bare project /Users/rgreen/git/project.git
    cd ~/code
    git clone --bare my_project /Users/rgreen/git/my_project.git

    # clone repo locally (see below for non-local)
    cd ~/code
    git clone /Users/rgreen/git/project.git
    git remote set-url origin /Users/rgreen/git/project.git
    git clone /Users/rgreen/git/my_project.git
    cd my_project
    git remote set-url origin /Users/rgreen/git/my_project.git

    # clone repo non-locally (see above for local)
    cd ~/code
    git clone rons-imac.local:/Users/rgreen/git/project.git
    git remote set-url origin rons-imac.local:/Users/rgreen/git/project.git
    git clone rons-imac.local:/Users/rgreen/git/my_project.git
    cd my_project
    git clone rons-imac.local:/Users/rgreen/git/my_project.git
    git remote set-url origin rons-imac.local:/Users/rgreen/git/my_project.git
    ```
  5. rgreenjr revised this gist Aug 21, 2018. 1 changed file with 11 additions and 3 deletions.
    14 changes: 11 additions & 3 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -171,8 +171,16 @@ git rebase master
    ## Hosting Non-Public Repos

    ```sh
    git clone --bare my_project /Users/rgreen/git/my_project.git
    # make bare copy of repo
    git clone --bare project /Users/rgreen/git/project.git

    # clone repo locally (see below for non-local)
    cd ~/code
    git clone /Users/rgreen/git/project.git
    git remote set-url origin /Users/rgreen/git/project.git

    # clone repo non-locally (see above for local)
    cd ~/code
    git clone /Users/rgreen/git/my_project.git
    git remote set-url origin /Users/rgreen/git/my_project.git
    git clone rons-imac.local:/Users/rgreen/git/project.git
    git remote set-url origin rons-imac.local:/Users/rgreen/git/project.git
    ```
  6. rgreenjr revised this gist Aug 21, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -172,6 +172,7 @@ git rebase master

    ```sh
    git clone --bare my_project /Users/rgreen/git/my_project.git
    cd ~/code
    git clone /Users/rgreen/git/my_project.git
    git remote set-url origin /Users/rgreen/git/my_project.git
    ```
  7. rgreenjr revised this gist Aug 21, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -171,5 +171,7 @@ git rebase master
    ## Hosting Non-Public Repos

    ```sh
    git clone --bare my_project ~/code/my_project.git
    git clone --bare my_project /Users/rgreen/git/my_project.git
    git clone /Users/rgreen/git/my_project.git
    git remote set-url origin /Users/rgreen/git/my_project.git
    ```
  8. rgreenjr revised this gist Aug 21, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -165,4 +165,11 @@ git merge upstream/master
    # if there were any new commits, rebase your development branch
    git checkout FEATURE_BRANCH
    git rebase master
    ```


    ## Hosting Non-Public Repos

    ```sh
    git clone --bare my_project ~/code/my_project.git
    ```
  9. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -122,7 +122,8 @@ git merge --no-ff branch_name

    ## Contributing to Open Source

    [How to Rebase a Pull Request](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request)
    - [How to Rebase a Pull Request](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request)
    - [GitHub Standard Fork & Pull Request Workflow](https://gist.github.com/Chaser324/ce0505fbed06b947d962)

    ### Creating a Fork

  10. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # Git Cheat Sheet

    ## Common Commands

    ```sh
    # stage all modified files being tracked
    git add -u
    @@ -116,14 +120,11 @@ git checkout development
    git merge --no-ff branch_name
    ```


    # How to Rebase a Pull Request

    https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request


    ## Contributing to Open Source

    [How to Rebase a Pull Request](https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request)

    ### Creating a Fork

    ```sh
    # clone the origianl repo
  11. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 66 additions and 6 deletions.
    72 changes: 66 additions & 6 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -3,104 +3,164 @@
    git add -u
    ```

    ```sh
    # revert file
    git checkout -- filepath
    ```

    ```sh
    # change comment of last commit
    git commit --amend
    ```

    ```sh
    # unstage all files
    git reset HEAD
    ```

    ```sh
    # unstage one file
    git reset HEAD -- filepath
    ```

    ```sh
    # undo last commit (leaving files in index)
    git reset --soft HEAD~

    ```

    ```sh
    # undo last commit and unstage all files
    git reset HEAD~
    ```

    ```sh
    # revert to last local commit (throwing away changes)
    git reset --hard
    ```

    ```sh
    # revert changes of a merge
    git reset --hard ORIG_HEAD
    ```

    ```sh
    # show difference between the HEAD and the index
    git diff --staged
    ```

    ```sh
    # show diff between HEAD and both staged and unstaged changes (what would be committed with 'git commit -a')
    git diff HEAD
    ```

    ```sh
    # diff two branches
    git diff --stat branch1...branch2
    ```

    ```sh
    # show history
    git log --graph --oneline
    ```

    ```sh
    # find the most recent common ancestor of two branches
    git merge-base branch1 branch2
    ```

    ```sh
    # remove deleted files from git
    git status | grep deleted | awk '{print \$3}' | xargs git rm
    ```

    ```sh
    # show information about your remotes
    git remote show origin
    ```

    ```sh
    # set up tracking remote branch
    git remote add origin [email protected]:rgreenjr/foobar.git
    ```

    ```sh
    # push local branch with tracking to remote repo
    git push -u origin FEATURE_BRANCH
    ```

    ```sh
    # pull remote branch to local repo
    git fetch origin
    git checkout --track origin/branch_name
    ```

    ```sh
    # delete remote branch
    git push origin --delete branch_name
    ```

    ```sh
    # cleanup stale remote branches
    git remote prune origin
    ```

    ```sh
    # rebase development branch onto local feature branch (usually prior to merging feature branch onto development branch)
    git checkout branch_name
    git rebase development
    ```

    ```sh
    # merge local feature branch onto development without fast-forwarding
    git checkout development
    git merge --no-ff branch_name
    ```


    # How to Rebase a Pull Request

    https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request

    #############################
    # contributing to open source
    #############################

    ## Contributing to Open Source


    ```sh
    # clone the origianl repo
    git clone [email protected]:USERNAME/FORKED_PROJECT.git
    ```

    ```sh
    # add 'upstream' repo to list of remotes
    git remote add upstream [email protected]:UPSTREAM_USER/ORIGINAL_PROJECT.git
    ```

    ```sh
    # verify the new remote named 'upstream'
    git remote -v
    ```

    ```sh
    # create a new branch
    git checkout -b FEATURE_BRANCH
    ```

    ```sh
    # push new feature branch to cloned repo with tracking
    git push -u origin FEATURE_BRANCH
    ```

    # submitting a pull request
    ### Submitting a Pull Request

    ```sh
    # fetch upstream master and merge with your repo's master branch
    git fetch upstream
    git checkout master
    git merge upstream/master
    ```

    ```sh
    # if there were any new commits, rebase your development branch
    git checkout FEATURE_BRANCH
    git rebase master
    git rebase master
    ```
  12. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    # stage all modified files being tracked

    ```sh
    # stage all modified files being tracked
    git add -u
    ```

  13. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    # stage all modified files being tracked

    ```sh
    git add -u
    ```

    # revert file
    git checkout -- filepath
  14. rgreenjr renamed this gist Aug 15, 2017. 1 changed file with 4 additions and 25 deletions.
    29 changes: 4 additions & 25 deletions git_cheat_sheet.sh → Git Cheat Sheet.md
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ git remote show origin
    git remote add origin [email protected]:rgreenjr/foobar.git

    # push local branch with tracking to remote repo
    git push -u origin branch_name
    git push -u origin FEATURE_BRANCH

    # pull remote branch to local repo
    git fetch origin
    @@ -70,33 +70,9 @@ git rebase development
    git checkout development
    git merge --no-ff branch_name

    #############################
    # contributing to open source
    #############################

    # clone the origianl repo
    git clone [email protected]/foobar/foobar.git --recursive
    git remote add upstream [email protected]:foobar/foobar.git

    # create a new branch
    git checkout -b new_branch

    # push new branch to cloned repo with tracking
    git push -u origin new_branch

    # pull and rebase before issuing pull request
    git checkout master
    git fetch upstream
    git merge upstream/master
    git checkout new_branch
    git rebase master
    git push

    # How to Rebase a Pull Request
    https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request



    #############################
    # contributing to open source
    #############################
    @@ -113,6 +89,9 @@ git remote -v
    # create a new branch
    git checkout -b FEATURE_BRANCH

    # push new feature branch to cloned repo with tracking
    git push -u origin FEATURE_BRANCH

    # submitting a pull request

    # fetch upstream master and merge with your repo's master branch
  15. rgreenjr revised this gist Aug 15, 2017. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -94,3 +94,32 @@ git push

    # How to Rebase a Pull Request
    https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request



    #############################
    # contributing to open source
    #############################

    # clone the origianl repo
    git clone [email protected]:USERNAME/FORKED_PROJECT.git

    # add 'upstream' repo to list of remotes
    git remote add upstream [email protected]:UPSTREAM_USER/ORIGINAL_PROJECT.git

    # verify the new remote named 'upstream'
    git remote -v

    # create a new branch
    git checkout -b FEATURE_BRANCH

    # submitting a pull request

    # fetch upstream master and merge with your repo's master branch
    git fetch upstream
    git checkout master
    git merge upstream/master

    # if there were any new commits, rebase your development branch
    git checkout FEATURE_BRANCH
    git rebase master
  16. rgreenjr revised this gist Mar 8, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -90,7 +90,6 @@ git fetch upstream
    git merge upstream/master
    git checkout new_branch
    git rebase master
    git checkout new_branch
    git push

    # How to Rebase a Pull Request
  17. rgreenjr revised this gist Mar 7, 2016. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -76,21 +76,22 @@ git merge --no-ff branch_name

    # clone the origianl repo
    git clone [email protected]/foobar/foobar.git --recursive

    # add repo as upstream
    git remote add upstream [email protected]:foobar/foobar.git
    git fetch upstream
    git merge upstream/master

    # create a new branch
    git checkout -b new_branch_name
    git checkout -b new_branch

    # push new branch to cloned repo with tracking
    git push -u origin new_branch_name
    git push -u origin new_branch

    # pull and rebase before issuing pull request
    git checkout master
    git fetch upstream
    git merge upstream/master
    git checkout new_branch_name
    git checkout new_branch
    git rebase master
    git checkout new_branch
    git push

    # How to Rebase a Pull Request
    https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request
  18. rgreenjr revised this gist Mar 7, 2016. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -70,10 +70,27 @@ git rebase development
    git checkout development
    git merge --no-ff branch_name

    #############################
    # contributing to open source
    #############################

    # clone the origianl repo
    git clone [email protected]/foobar/foobar.git --recursive

    # add repo as upstream
    git remote add upstream [email protected]:foobar/foobar.git
    git fetch upstream
    git merge upstream/master

    # create a new branch
    git checkout -b new_branch_name

    # push new branch to cloned repo with tracking
    git push -u origin new_branch_name

    # pull and rebase before issuing pull request
    git checkout master
    git fetch upstream
    git merge upstream/master
    git checkout new_branch_name
    git rebase master
  19. rgreenjr revised this gist Mar 7, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -76,4 +76,4 @@ git remote add upstream [email protected]:foobar/foobar.git
    git fetch upstream
    git merge upstream/master
    git checkout -b new_branch_name
    git push origin new_branch_name
    git push -u origin new_branch_name
  20. rgreenjr revised this gist Mar 7, 2016. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -68,4 +68,12 @@ git rebase development

    # merge local feature branch onto development without fast-forwarding
    git checkout development
    git merge --no-ff branch_name
    git merge --no-ff branch_name

    # contributing to open source
    git clone [email protected]/foobar/foobar.git --recursive
    git remote add upstream [email protected]:foobar/foobar.git
    git fetch upstream
    git merge upstream/master
    git checkout -b new_branch_name
    git push origin new_branch_name
  21. rgreenjr revised this gist Mar 2, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ git reset HEAD
    # unstage one file
    git reset HEAD -- filepath

    # undo last commit (but leave files in index)
    # undo last commit (leaving files in index)
    git reset --soft HEAD~

    # undo last commit and unstage all files
  22. rgreenjr revised this gist Mar 2, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ git reset HEAD
    # unstage one file
    git reset HEAD -- filepath

    # undo last commit (wihtout unstaging)
    # undo last commit (but leave files in index)
    git reset --soft HEAD~

    # undo last commit and unstage all files
  23. rgreenjr revised this gist Mar 2, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,13 @@ git reset HEAD
    # unstage one file
    git reset HEAD -- filepath

    # revert to last local commit
    # undo last commit (wihtout unstaging)
    git reset --soft HEAD~

    # undo last commit and unstage all files
    git reset HEAD~

    # revert to last local commit (throwing away changes)
    git reset --hard

    # revert changes of a merge
  24. rgreenjr revised this gist Mar 2, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ git checkout -- filepath
    # change comment of last commit
    git commit --amend

    # unstage all file
    # unstage all files
    git reset HEAD

    # unstage one file
  25. rgreenjr revised this gist Mar 2, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion git_cheat_sheet.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,13 @@ git add -u
    # revert file
    git checkout -- filepath

    # unstage file
    # change comment of last commit
    git commit --amend

    # unstage all file
    git reset HEAD

    # unstage one file
    git reset HEAD -- filepath

    # revert to last local commit
  26. rgreenjr renamed this gist Sep 8, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  27. rgreenjr revised this gist Dec 4, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Git Cheat Sheet
    Original file line number Diff line number Diff line change
    @@ -54,6 +54,6 @@ git remote prune origin
    git checkout branch_name
    git rebase development

    # merge local feature branch into development
    # merge local feature branch onto development without fast-forwarding
    git checkout development
    git merge branch_name
    git merge --no-ff branch_name
  28. rgreenjr revised this gist Dec 4, 2014. 1 changed file with 11 additions and 3 deletions.
    14 changes: 11 additions & 3 deletions Git Cheat Sheet
    Original file line number Diff line number Diff line change
    @@ -38,14 +38,22 @@ git remote show origin
    git remote add origin [email protected]:rgreenjr/foobar.git

    # push local branch with tracking to remote repo
    git push -u origin branch
    git push -u origin branch_name

    # pull remote branch to local repo
    git fetch origin
    git checkout --track origin/branch
    git checkout --track origin/branch_name

    # delete remote branch
    git push origin --delete branch
    git push origin --delete branch_name

    # cleanup stale remote branches
    git remote prune origin

    # rebase development branch onto local feature branch (usually prior to merging feature branch onto development branch)
    git checkout branch_name
    git rebase development

    # merge local feature branch into development
    git checkout development
    git merge branch_name
  29. rgreenjr revised this gist Oct 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Git Cheat Sheet
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ git remote show origin
    # set up tracking remote branch
    git remote add origin [email protected]:rgreenjr/foobar.git

    # push local branch to remote repo
    # push local branch with tracking to remote repo
    git push -u origin branch

    # pull remote branch to local repo
  30. rgreenjr revised this gist Oct 3, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Git Cheat Sheet
    Original file line number Diff line number Diff line change
    @@ -46,3 +46,6 @@ git checkout --track origin/branch

    # delete remote branch
    git push origin --delete branch

    # cleanup stale remote branches
    git remote prune origin