{"id":13578628,"url":"https://github.com/susam/gitpr","last_synced_at":"2025-05-14T23:15:50.853Z","repository":{"id":50320490,"uuid":"121846490","full_name":"susam/gitpr","owner":"susam","description":"Quick reference guide on fork and pull request workflow","archived":false,"fork":false,"pushed_at":"2024-02-13T05:17:17.000Z","size":71,"stargazers_count":960,"open_issues_count":1,"forks_count":85,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-05T19:35:14.727Z","etag":null,"topics":["git","guide","pull-request","workflow"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/susam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-17T10:35:49.000Z","updated_at":"2025-04-05T15:50:06.000Z","dependencies_parsed_at":"2024-11-05T16:52:41.022Z","dependency_job_id":null,"html_url":"https://github.com/susam/gitpr","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fgitpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fgitpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fgitpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/susam%2Fgitpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/susam","download_url":"https://codeload.github.com/susam/gitpr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243314,"owners_count":22038048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","guide","pull-request","workflow"],"created_at":"2024-08-01T15:01:32.358Z","updated_at":"2025-05-14T23:15:50.832Z","avatar_url":"https://github.com/susam.png","language":"Makefile","readme":"Fork and Pull Request Workflow\n==============================\n\n\u003c!-- :: \\iffalse --\u003e\n[![Download PDF][SHIELD_PDF]][DOWNLOAD_PDF]\n[![Download TXT][SHIELD_TXT]][DOWNLOAD_TXT]\n[![CC BY 4.0 License][SHIELD_CCBY]][CCBY]\n\u003c!-- :: --\u003e\n[SHIELD_PDF]: https://img.shields.io/badge/download-PDF-brightgreen.svg\n[SHIELD_TXT]: https://img.shields.io/badge/download-TXT-brightgreen.svg\n[SHIELD_CCBY]: https://img.shields.io/badge/license-CC%20BY%204.0-blue.svg\n[DOWNLOAD_PDF]: https://github.com/susam/gitpr/releases/download/0.6.0/gitpr.pdf\n[DOWNLOAD_TXT]: https://github.com/susam/gitpr/releases/download/0.6.0/gitpr.txt\n\u003c!-- :: \\fi --\u003e\n\u003c!-- Version 0.6.0 (2018-11-19) --\u003e\n\u003c!-- :: \\maketitle --\u003e\n\nThis document describes how developers may contribute pull requests to\nan upstream repository and how upstream owners may merge pull requests\nfrom contributors according to the very popular fork and pull request\nworkflow followed in many projects on GitHub.\n\nThe download buttons above download version 0.6.0 \u003c!-- x --\u003e\n(the latest stable release) of this document. \u003c!-- x --\u003e\n\u003c!-- x --\u003e\nThe most recent version of this document is available at\n[git.io/gitpr](https://git.io/gitpr).\n\n\u003c!-- :: \\iffalse --\u003e\n\nContents\n--------\n\n* [Introduction](#introduction)\n* [Quick Reference](#quick-reference)\n* [Create Pull Request](#create-pull-request)\n  * [Fork and Clone](#fork-and-clone)\n  * [Work on Pull Request](#work-on-pull-request)\n  * [Keep Your Fork Updated](#keep-your-fork-updated)\n  * [Amend Last Commit](#amend-last-commit)\n  * [Rebase Commits](#rebase-commits)\n  * [Edit Commits](#edit-commits)\n  * [Force Push](#force-push)\n  * [Delete Branch](#delete-branch)\n* [Merge Pull Request](#merge-pull-request)\n  * [Without Merge Commit](#without-merge-commit)\n  * [With Merge Commit](#with-merge-commit)\n* [Nifty Commands](#nifty-commands)\n  * [Pretty Log](#pretty-log)\n  * [Staged Diff](#staged-diff)\n  * [Branch Listing](#branch-listing)\n  * [More Aliases](#more-aliases)\n  * [Merge Base](#merge-base)\n  * [Commit Partial Changes](#commit-partial-changes)\n  * [Some Git Wisdom](#some-git-wisdom)\n* [License](#license)\n* [Support](#support)\n\n\u003c!-- :: \\fi --\u003e\n\u003c!-- :: \\tableofcontents --\u003e\n\u003c!-- :: \\pagebreak --\u003e\n\nIntroduction\n------------\n\nEvery project has a main development branch where the developers push\ncommits on a day-to-day basis. Usually, the main development branch is\n`master` but some projects choose to have `develop` or `trunk` or\nanother branch for day-to-day development activities. We refer to this\nmain development branch as the *main development branch* throughout this\ndocument to keep the text general. However in the command examples and\nASCII-diagrams, we use `master` as an example of the main development\nbranch.\n\nWe use the following placeholders in the command examples and\nASCII-diagrams in this document:\n\n  - `GITHUB`: [`github.com`](https://github.com/) or domain\n    name/hostname of your private GitHub Enterprise system.\n  - `USER` or `CONTRIBUTOR`: The user that forks an upstream repository,\n    creates pull requests, and sends them to the upstream repository.\n  - `UPSTREAM-OWNER`: Owner of the upstream repository. This is the name\n    of the user or organization that merges pull requests into the\n    upstream repository.\n  - `REPO`: Repository name.\n  - `FILES`: One or more filenames to be staged for a commit.\n  - `TOPIC-BRANCH`: Feature-specific or bug-specific branch where a\n    contributor develops her or his contribution. This is referred to as\n    the *topic branch* in the text.\n\nThese placeholders should be substituted with appropriate values while\nexecuting the commands presented in this document.\n\nBeginners to this workflow should always remember that a Git branch is\nnot a container of commits, but rather a lightweight moving pointer that\npoints to a commit in the commit history.\n\n    A---B---C\n            ↑\n         (master)\n\nWhen a new commit is made in a branch, its branch pointer simply moves\nto point to the last commit in the branch.\n\n    A---B---C---D\n                ↑\n             (master)\n\nA branch is merely a pointer to the tip of a series of commits. With\nthis little thing in mind, seemingly complex operations like rebase and\nfast-forward merges become easy to understand and use.\n\nThe next section, *[Quick Reference](#quick-reference)*, provides a brief\nsummary of all the frequently used commands involved in creating and merging\npull requests.\n\n\u003c!-- :: \\pagebreak --\u003e\n\n\nQuick Reference\n---------------\n\nHere is a brief summary of all the commands used to create and merge\npull requests in this document. This section serves as a quick\nreference.\n\n    # CREATE PULL REQUEST\n    # ===================\n    # Fork upstream and clone your fork.\n    git clone https://GITHUB/USER/REPO.git\n    cd REPO\n    git remote add upstream https://GITHUB/UPSTREAM-OWNER/REPO.git\n    git remote -v\n\n    # Work on pull request in a new topic branch.\n    git checkout -b TOPIC-BRANCH\n    git add FILES\n    git commit\n    git push origin TOPIC-BRANCH\n\n    # Go to your fork on GitHub, switch to the topic branch, and\n    # click *Compare \u0026 pull request*.\n\n    # Keep your fork's main development branch updated with upstream's.\n    git checkout master\n    git pull upstream master\n    git push origin master\n\n    # Amend last commit (optional).\n    git add FILES\n    git commit --amend\n\n    # Rebase topic branch on the main development branch (optional).\n    git checkout TOPIC-BRANCH\n    git rebase master\n\n    # Edit commits, e.g., last 3 commits in topic branch (optional).\n    git checkout TOPIC-BRANCH\n    git rebase -i HEAD~3\n\n    # Force push rebased/edited commits to the pull request (optional).\n    git push -f origin TOPIC-BRANCH\n\n    # Delete topic branch branch after pull request is merged.\n    git checkout master\n    git branch -D TOPIC-BRANCH\n    git push -d origin TOPIC-BRANCH\n\n\u003c!-- :: \\pagebreak --\u003e\n\n    # MERGE PULL REQUEST (WITHOUT MERGE COMMIT)\n    # =========================================\n    # Clone upstream repo.\n    git clone https://GITHUB/UPSTREAM-OWNER/REPO.git\n    cd REPO\n\n    # Keep the local main development branch up-to-date.\n    git checkout master\n    git pull\n\n    # Pull changes in pull request into a temporary branch.\n    git checkout -b pr\n    git pull https://GITHUB/CONTRIBUTOR/REPO.git TOPIC-BRANCH\n\n    # If the above command does not create a new merge commit, ignore\n    # this comment and follow the remaining commands after this comment.\n    #\n    # If the above command creates a new merge commit, first consider\n    # that it is okay to have a merge commit. However, if you want to\n    # get rid of it, choose exactly one of the following three options:\n    #\n    #   - Request the contributor to rebase the topic branch on the main\n    #     development branch. After the contributor has done so, delete\n    #     the temporary branch, start over, and pull the changes again.\n    #     (Commands: git checkout master; git branch -D pr)\n    #\n    #   - Go to the pull request page on GitHub, click on the dropdown\n    #     menu next to 'Merge pull request', select 'Rebase and merge',\n    #     and click 'Rebase and merge'.\n    #\n    #   - Rebase the topic branch on the main development branch. Then\n    #     follow the commands below. Finally close the pull request on\n    #     GitHub manually. (Command: git rebase master)\n\n    # Merge pull request and delete temporary branch.\n    git checkout master\n    git merge pr\n    git branch -d pr\n\n    # Push the updated main development branch to upstream repo.\n    git push origin master\n\n\u003c!-- :: \\pagebreak --\u003e\n\n    # MERGE PULL REQUEST (WITH MERGE COMMIT)\n    # ======================================\n    # Clone upstream repo.\n    git clone https://GITHUB/UPSTREAM-OWNER/REPO.git\n    cd REPO\n\n    # Keep the local main development branch up-to-date.\n    git checkout master\n    git pull\n\n    # Pull changes in pull request into a temporary branch.\n    git checkout -b pr\n    git pull https://GITHUB/CONTRIBUTOR/REPO.git TOPIC-BRANCH\n\n    # Merge pull request and delete temporary branch.\n    git checkout master\n    git merge --no-ff pr\n    git branch -d pr\n\n    # Push the updated main development branch to upstream repo.\n    git push origin master\n\nThe next two sections, *[Create Pull Request](#create-pull-request)*\nand *[Merge Pull Request](#merge-pull-request)*, elaborate these\ncommands in detail.\n\n\u003c!-- :: \\pagebreak --\u003e\n\nCreate Pull Request\n-------------------\n\nThis section is meant for developers who contribute new commits to the\nupstream repository from their personal fork.\n\n\n### Fork and Clone\n\nOn GitHub, fork the upstream repository to your personal user account.\n\nThen clone your fork from your personal GitHub user account to your\nlocal system and set the upstream repository URL as a remote named\n`upstream`.\n\n    git clone https://GITHUB/USER/REPO.git\n    cd REPO\n    git remote add upstream https://GITHUB/UPSTREAM-OWNER/REPO.git\n    git remote -v\n\nNow the remote named `upstream` points to the upstream repository and\nthe remote named `origin` points to your fork.\n\n\n### Work on Pull Request\n\nWork on a new pull request in a new topic branch and commit it to your\nfork. Remember to use a meaningful name instead of `TOPIC-BRANCH` in the\ncommands below.\n\n    git checkout -b TOPIC-BRANCH\n    git add FILES\n    git commit\n    git push origin TOPIC-BRANCH\n\nCreate pull request via GitHub web interface as per the following steps:\n\n  - Go to your fork on GitHub.\n  - Switch to the topic branch.\n  - Click *Compare \u0026 pull request*.\n  - Click *Create pull request*.\n\nWait for an upstream developer to review and merge your pull request.\n\nIf there are review comments to be addressed, continue working on your\nbranch, commiting, optionally rebasing, amending, squashing, and\ndropping them, and pushing them to the topic branch of `origin` (your\nfork). Any changes to the topic branch automatically become available in\nthe pull request.\n\nIn the fork and pull request workflow, a contributor should never commit\nanything to the main development branch of personal fork. This makes it\nvery easy to keep the main development branch of your fork in sync with\nthat of the upstream repository. This is explained in the next\nsubsection.\n\n\u003c!-- :: \\pagebreak --\u003e\n\n### Keep Your Fork Updated\n\nAs new pull requests get merged into the upstream's main development\nbranch, the main development branch of your fork begins falling behind\nit.\n\nThe commands below show how to update your fork's main development\nbranch with the new commits in the upstream's main development branch.\n\n    git checkout master\n    git pull upstream master\n    git push origin master\n\nThe `git pull` command above simply fast-forwards the main development\nbranch from an earlier commit to the last commit in the upstream's main\ndevelopment branch.\n\nWhen your main development branch falls behind the upstream's main\ndevelopment branch, the upstream's main development branch extends\nlinearly from the last commit in your main development branch, provided\nthat there are no additional commits to your main development branch\nthat has caused it to diverge.\n\n                  E---F---G  (TOPIC-BRANCH)\n                 /\n    A---B---C---D  (master)\n                 \\\n                  H---I---J  (upstream/master)\n\n\nWith such a commit history, when the upstream's main development branch\nis merged into your main development branch, the merge is done by simply\nfast-forwarding the pointer of your main development branch to the last\ncommit in the upstream's main development branch.\n\n                  E---F---G  (TOPIC-BRANCH)\n                 /\n    A---B---C---D\n                 \\\n                  H---I---J  (upstream/master, master)\n\nAfter the merge is complete, the upstream's main development branch and\nyour main development branch point to the same commit.\n\n\u003c!-- :: \\pagebreak --\u003e\n\n### Amend Last Commit\n\nThis is an optional step to rework on the last commit. After commiting\nsome work, one may realize that some files need to be modified or the\ncommit message needs to updated.\n\n         E---F---G  (TOPIC-BRANCH)\n        /\n    A---B---C---D   (master)\n\nGit allows us to pick the last commit, modify the changes made in that\ncommit including the commit message, and reapply the changes along with\nthe modifications as a new commit that replaces the last commit.\n\n         E---F---G' (TOPIC-BRANCH)\n        /\n    A---B---C---D   (master)\n\nTo do so, first rework on the files and make the necessary changes. Then\nadd, remove, move, or rename files to stage them for commiting. Finally,\namend the last commit. The commit message may be modified when the\neditor comes up to show the commit message.\n\n    git add FILES\n    git commit --amend\n\nAlthough the above example shows only the `git add` command to add new\nor modified files for commiting, one may amend the last commit by\nremoving, moving, and renaming files with the `git rm` and `git mv`\ncommands before amending the last commit.\n\nTo update only the commit message without changing files, run only `git\ncommit --amend`.\n\n\n### Rebase Commits\n\nThis is an optional step to keep the commit history as linear as possible.\n\nThe main development branch may have diverged since the topic branch was\ncreated.\n\n         E---F---G (TOPIC-BRANCH)\n        /\n    A---B---C---D  (master)\n\nIt may be a good idea to move the commits in the topic branch and place\nthem on top of the main development branch, so that the topic branch\nextends linearly from the last commit in the main development branch.\n\n                  E'--F'--G' (TOPIC-BRANCH)\n                 /\n    A---B---C---D  (master)\n\nThe following commands show how to rebase the topic branch on the main\ndevelopment branch.\n\n    git checkout TOPIC-BRANCH\n    git rebase master\n\n\n### Edit Commits\n\nThis is an optional step to keep the commit history clean and concise.\n\nA pull request may contain multiple commits. Sometimes one may need to\namend a commit that is not the last commit in the pull request. Commits\nprior to the last commit can be amended with the interactive rebase\ncommand.\n\nAfter developing the required feature or bug-fix in a topic branch, the\ndeveloper or a reviewer may notice issues in the work that need to be\naddressed before the pull request can be merged into the upstream\nrepository. This may lead to multiple new commits in the topic branch\nthat should ideally have been part of the first commit that implemented\nthat feature or bug-fix.\n\n         E---F---G (TOPIC-BRANCH)\n        /\n    A---B---C---D  (master)\n\nIn such cases, it may be a good idea to squash multiple commits in the\ntopic branch into a single coherent commit with all changes for the\nfeature or bug-fix being developed.\n\n         E'        (TOPIC-BRANCH)\n        /\n    A---B---C---D  (master)\n\nThe following example shows how to amend the last 3 commits.\n\n    git checkout TOPIC-BRANCH\n    git rebase -i HEAD~3\n\nThis brings up an editor with three lines for the last 3 commits ordered\nfrom earliest to last followed by instructions on how to edit these\nlines to amend the commits.\n\nFor example, to squash all three commits into one, leave the first\ncommit untouched, replace `pick` with `squash` in the next two lines,\nsave, and quit the editor. This brings up the editor again. Clean up the\ncommit message, save, and quit the editor.\n\nApart from `pick` and `squash`, there are other operations such as\n`reword`, `edit`, `drop`, etc. to amend or drop commits. Follow the\ninstructions that appear in the editor to use them. When a rebase\noperation involves multiple steps, Git walks you through each step by\noffering suggestions and commands that you need to use in each step.\n\n\u003c!-- :: \\pagebreak --\u003e\n\n### Force Push\n\nThe steps in the last three sections overwrite the history of the\nbranch. If these steps are performed after the pull request branch has\nalready been pushed to GitHub, then it is necessary to use the `-f` or\n`--force` option to push the overwritten history to GitHub.\n\n    git push -f origin TOPIC-BRANCH\n\nThe `-f` (force) option in the `git push` command is necessary only if\nyou are pushing to an already existing pull request branch because doing\nso overwrites the history of the branch. Normally, overwriting history\nis strictly discouraged but this is one of the rare scenarios where it\nis safe to overwrite the commit history because the commits are being\npushed to a personal branch in a personal fork without affecting the\nupstream repository.\n\n\n### Delete Branch\n\nOnce the upstream developer merges your pull request, you may delete the\ntopic branch from your local system as well as from your fork.\n\n    git checkout master\n    git branch -D TOPIC-BRANCH\n    git push -d origin TOPIC-BRANCH\n\nThe next section, *[Merge Pull Request](#merge-pull-request)*, explains how an\nupstream owner can merge pull request from contributors into the upstream\nrepository.\n\n\u003c!-- :: \\pagebreak --\u003e\n\nMerge Pull Request\n------------------\n\nThis section is meant for lead developers who own the upstream\nrepository and merge pull requests from contributors to it.\n\nThere are two popular methods to merge commits: one that does not\nintroduce an additional merge commit, and another that does. Both are\nperfectly acceptable. Both are discussed below.\n\nWhich method you choose depends on whether you want to maintain a\nconcise commit history consisting only of development commits or if you\nwant to introduce additional merge commits for every merge into your\ncommit history.\n\n\n### Without Merge Commit\n\nClone the upstream repository to your local system.\n\n    git clone https://GITHUB/UPSTREAM-OWNER/REPO.git\n    cd REPO\n\nIf the repository was already cloned to the local system earlier, then\nensure that the local main development branch is up-to-date with that in\nthe upstream repository.\n\n    git checkout master\n    git pull\n\nCreate a temporary branch (`pr` for example) to pull the contribution\n(pull request) from the CONTRIBUTOR's branch in it.\n\n    git checkout -b pr\n    git pull https://GITHUB/CONTRIBUTOR/REPO.git TOPIC-BRANCH\n\nIf the main development branch has diverged from the branch in the pull\nrequest, the above command creates a new merge commit to merge the pull\nrequest into the temporary branch.\n\nNote: It is okay to have a merge commit while merging pull requests.\nThere is nothing wrong about it. If you are comfortable having a merge\ncommit for the pull request, skip the list of three points below and\ncontinue with merging the pull request.\n\nIf you really want to get rid of the additional merge commit, follow\nexactly one of these options:\n\n  - Request the contributor to rebase the topic branch on the main\n    development branch. See the *[Rebase Commits](#rebase-commits)*\n    section for more details. After the contributor has rebased the\n    topic branch on the main development branch, delete the temporary\n    branch.\n\n        git checkout master\n        git branch -D pr\n\n    Then start over and pull the pull request again. In fact, if at any\n    time the contributor rebases the pull request, or edits, squashes,\n    amends, or drops commits in the pull request, delete the temporary\n    branch and start over, and pull the pull request again.\n\n  - Go to the pull request page on GitHub, click on the dropdown menu\n    next to the *Merge pull request* button, select *Rebase and merge*,\n    and click *Rebase and merge*.\n\n    Caveat: The rebase operation rewrites the commit history of the pull\n    request submitted by the contributor. As a result, it modifies the\n    commit hash, committer, and commit date of each change in the pull\n    request. The committer and commit date fields are separate from the\n    author and author date fields. Use `git log --format=fuller` to see\n    all four fields.\n\n    This caveat is usually not a major problem because the author and\n    author date still remain intact. Further since the rebase and merge\n    is done via GitHub, it closes the pull request successfully and sets\n    its status to *Merged*.\n\n    However if you are not comfortable with the committer details\n    changing, then do not choose this option and choose the previous\n    option instead.\n\n  - Rebase the pull request on the main development branch as explained\n    in the *[Rebase Commits](#rebase-commits)* section.\n\n    Caveat: In addition to the caveat mentioned in the previous point,\n    in this case, GitHub remains oblivious of the changed commit hashes\n    because the rebase operation is done locally, not via GitHub.\n    Therefore after the merged pull request is pushed to the upstream\n    repository, GitHub does not close the pull request.\n\n    The pull request on GitHub can then be closed manually but its\n    status would not appear as *Merged*. It would appear as *Closed*\n    instead. This can be confusing and misleading. Therefore this option\n    is not recommended. Choose one of the previous two options instead.\n\nAfter sufficient testing, merge the commits in the pull request into the\nmain development branch and remove the pull request branch.\n\n    git checkout master\n    git merge pr\n    git branch -d pr\n\nFinally, push the current state of the main development branch to the\nupstream repository.\n\n    git push origin master\n\nThe `git merge` command above simply fast-forwards the main development\nbranch from an earlier commit to the last commit in the pull request\nthereby making both the main development branch and the pull request\nbranch point to the same commit. This achieves the merge from the pull\nrequest branch into the main development branch without creating a new\nmerge commit.\n\nAfter a pull request branch is rebased on the main development branch,\nthe pull request branch becomes a linear extension of the main\ndevelopment branch.\n\n                  E'---F'---G' (pr)\n                 /\n    A---B---C---D (master)\n\nWith such a commit history, when the pull request branch is now merged\ninto the main development branch, the merge is done by simply\nfast-forwarding the pointer of the main development branch to the last\ncommit in the pull request branch.\n\n                  E'---F'---G' (pr, master)\n                 /\n    A---B---C---D\n\n\u003c!-- :: \\pagebreak --\u003e\n\n### With Merge Commit\n\nClone the upstream repository to your local system.\n\n    git clone https://GITHUB/UPSTREAM-OWNER/REPO.git\n    cd REPO\n\nIf the repository was already cloned to the local system earlier, then\nensure that the local main development branch is up-to-date with that in\nthe upstream repository.\n\n    git checkout\n    git pull\n\nCreate a temporary branch (`pr` for example) to pull the contribution\n(pull request) from the CONTRIBUTOR's branch in it.\n\n    git checkout -b pr\n    git pull https://GITHUB/CONTRIBUTOR/REPO.git TOPIC-BRANCH\n\nIf the contributor adds new commits to the pull request later, then run\nthese commands again to pull the new commits.\n\nAfter sufficient testing, merge the commits in the pull request into the\nmain development branch.\n\n    git checkout master\n    git merge --no-ff pr\n    git branch -d pr\n\nFinally, push the current state of the main development branch (with the\ncommits from the pull request in it) to the upstream repository.\n\n    git push origin master\n\nThe `--no-ff` (no fast-forward) option in the `git merge` command\nensures that a merge commit is always created even when a fast-forward\nmerge is possible.\n\n                  E'---F'---G' (pr)\n                 /           \\\n    A---B---C---D-------------H (master)\n\n\u003c!-- :: \\pagebreak --\u003e\n\nNifty Commands\n--------------\n\nThis is a bonus section that describes a few aliases and commands that\nmay be useful during day-to-day development activities.\n\n\n### Pretty Log\n\nThe following commands create aliases to run `git log` with various subsets of\n{`--pretty`, `--graph`, `--all`} options to display commit logs in a compact\nform, i.e., one line per log.\n\n    # Define aliases.\n    git config --global pretty.fmt '%C(auto)%h %C(magenta)%ad %C(cyan)%an%C(auto)%d %s'\n    git config --global alias.lga 'log --pretty=fmt --date=short --graph --all'\n    git config --global alias.lg  'log --pretty=fmt --date=short --graph'\n    git config --global alias.la  'log --pretty=fmt --date=short --all'\n    git config --global alias.ll  'log --pretty=fmt --date=short'\n    git config --global alias.lf  'log --pretty=fuller --stat'\n\n    # Use aliases.\n    git lga\n    git lg\n    git la\n    git ll\n    git lf\n\n\n### Staged Diff\n\nWhile `git diff` shows the unstaged changes in the working directory, it\nis necessary to use the `--cached` option with `git diff` to see the\nchanges staged for the next commit. The following commands create\nconvenient aliases for this option.\n\n    # Define aliases.\n    git config --global alias.diffc \"diff --cached\"\n    git config --global alias.dc \"diff --cached\"\n\n    # Use aliases.\n    git diffc\n    git dc\n\n\u003c!-- :: \\pagebreak --\u003e\n\n### Branch Listing\n\nThe following commands provides aliases to list branches with verbose\ninformation. The second alias includes remote branches too in the\noutput.\n\n    # Define aliases.\n    git config --global alias.br \"branch -vv\"\n    git config --global alias.brr \"branch -vva\"\n\n    # Use aliases.\n    git br\n    git brr\n\n\n### More Aliases\n\nHere are a few more commands to define aliases for very frequently used\ncommands.\n\n    # Define aliases.\n    git config --global alias.co \"checkout\"\n    git config --global alias.cob \"checkout -b\"\n    git config --global alias.ca \"commit --amend\"\n\n    # Use aliases.\n    git co\n    git cob\n    git ca\n\n\n### Merge Base\n\nFind a common ancestor of two branches with this command. It helps to\nfind the commit after which two branches began diverging.\n\n    git merge-base upstream/master TOPIC-BRANCH\n\n\n### Commit Partial Changes\n\nSometimes when you are in the zone, you may make large sweeping changes\nto a file. However it is a good practice to create separate and small\ncommits for separate concerns. To select some changes in a file while\nignoring other changes in the same file for the next commit, stage the\nchanges interactively with this command.\n\n    git add -p\n\nThis command shows every change hunk one by one. Enter `y` to stage a\nhunk for the next commit, `n` to ignore it, and `s` to split the hunk\ninto multiple smaller hunks. Enter `?` to print help message about each\ninteractive option that can be entered.\n\n\n### Some Git Wisdom\n\nEnter one of the commands below in your command shell depending on your\noperating system, or just open the URL with your web browser.\n\n    open https://xkcd.com/1597/\n    xdg-open https://xkcd.com/1597/\n    start https://xkcd.com/1597/\n\n\nLicense\n-------\n\nCopyright \u0026copy; 2018 Susam Pal\n\n[![CC BY 4.0 Logo](meta/ccby.svg \"CC BY 4.0\")][CCBY]\n\u003c!-- :: --\u003e\nThis document is licensed under the\n[Creative Commons Attribution 4.0 International License][CCBY].\n\nYou are free to share the material in any medium or format and/or adapt\nthe material for any purpose, even commercially, under the terms of the\nCreative Commons Attribution 4.0 International (CC BY 4.0) License.\n\nThis document is provided **as-is and as-available,**\n**without representations or warranties of any kind,** whether\nexpress, implied, statutory, or other. See the\n[CC BY 4.0 Legal Code][CCBYLC] for details.\n\n[CCBY]: http://creativecommons.org/licenses/by/4.0/\n[CCBYLC]: https://creativecommons.org/licenses/by/4.0/legalcode\n\n\nSupport\n-------\n\nTo report bugs, suggest improvements, or ask questions,\n[create issues][ISSUES].\n\nTo contribute improvements to this document,\n[fork this project][REPO] and *[create pull request][PR]!* ;-)\n\n[ISSUES]: https://github.com/susam/gitpr/issues\n[REPO]: https://github.com/susam/gitpr\n[PR]: #create-pull-request\n","funding_links":[],"categories":["Makefile","Tutorial"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsusam%2Fgitpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsusam%2Fgitpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsusam%2Fgitpr/lists"}