Skip to content

Instantly share code, notes, and snippets.

@DManavi
Last active July 29, 2019 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DManavi/17903fe6cf1736614c05f942f63ef41c to your computer and use it in GitHub Desktop.
Save DManavi/17903fe6cf1736614c05f942f63ef41c to your computer and use it in GitHub Desktop.
Github/Git sync fork using rebase & branching - Open multiple pull request

Intro

I've start contributing on a closed-source project. The lead developer asked me to use the method below to contribute on this project.

I write this document to help all the people who are new on this method (See below) of contributing on git projects.

Method

  1. Fork the project from the upstream repository (I name the base repository, upstream).
  2. Clone the forked repository on your local machine.
  3. Add upstream which point to the upstream on the fork repository.
  4. Fetch upstream.
  5. Checkout the master branch & Create a new branch for each feature (Follow the git flow).
  6. Add files to this branch.
  7. Commit & push the code (Also the branch) into your source control.
  8. Open a pull request on the github/git provider.
  9. Add other features (Start from step 5).
  10. Fetch upstream.
  11. Each time a pull request resolved/closed/accepted, switch to the master branch and rebase it with upstream/master.
  12. Push commit information retrieved via rebase (commit history & ...).

How to do it in shell

Start from step 2.

# 2) Clone the code
$ git clone your-git-repository-url

# 3) Add upstream
$ git remote add upstream upstream-git-url

# 4) Fetch upstream
$ git fetch upstream

# 5) Create a new branch
$ git checkout master && git checkout -b your-new-branch-name

# 6) Add files
$ git add . && git add --all

# 7) Commit & push the code
$ git commit -m "your message goes here" && git push --set-upstream origin your-new-branch-name

# 8) Do it on github/git web interface. I don't know how to do this in CLI

# 10 & 11) After pull request resolved
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master

# 12) Push commit information
$ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment