Skip to content

Instantly share code, notes, and snippets.

@davidmoten
Last active November 28, 2023 22:22
Show Gist options
  • Save davidmoten/b52683a278778e16d029 to your computer and use it in GitHub Desktop.
Save davidmoten/b52683a278778e16d029 to your computer and use it in GitHub Desktop.
How to contribute to a project on GitHub

How to contribute to a project on GitHub

Fork the project to your account

Login to github, go to project and click on Fork

Clone from fork to local

git clone https://github.com/davidmoten/RxJava.git

Locally add the upstream project

git remote add upstream https://github.com/ReactiveX/RxJava.git

Get and merge latest changes from the upstream project

git pull upstream master

or

git fetch upstream
git merge upstream/master

Checkout a branch from upstream

git checkout -b 1.x upstream/1.x

Pull changes from upstream branch

git pull upstream 1.x

Make a local branch for the new feature

git branch newFeature
git checkout newFeature

Get branch from your fork

git checkout newFeature

Make changes and commit changes to new branch

git commit -m “some comment”

Squash last 5 commits on the feature

git rebase -i HEAD~5

Note that fixup is what you will use most of the time

Squash all commits on a branch

git checkout yourBranch
git reset $(git merge-base main $(git branch --show-current))
git add -A
git commit -m "squashed commit message"
git push -f

Push changes to new remote branch

git push origin newFeature

If you push before squashing commits you might want to make another branch and push that squashed.

Send pull request

Go to the fork on github and select the branch newFeature. Click on the Pull request button.

If pull request accepted then

git checkout master
git pull upstream master

Amend pull request after push

git checkout master
git pull upstream master
git checkout <branch>
git merge-base <branch> master
git rebase --interactive ${HASH}
git rebase origin/master
git push -f origin <branch>

Delete new branch

git branch -D newFeature
git push origin --delete newFeature

Test pull request from someone before merge

Go to Merge pull request button on GitHub and click on the link to the left labelled command line. The first option tells you what to do. For example:

git checkout -b maxamel-master master
git pull https://github.com/maxamel/rtree.git master
mvn clean install

Bring down a PR locally from upstream

git fetch upstream pull/<ID>/head:<NEW_BRANCH>

Fetch all branches from origin and remote

git fetch --all

Fetch tags from upstream

git fetch upstream --tags

Tags are used by some builds to decide what version to give the current build.

Behind by n commits

git checkout master
git remote update origin
git pull origin master

Reset origin branch to be as upstream

git remote update
# the double hyphen ensures that upstream/master is
# considered as a revision and not confused as a path
git reset --hard upstream/master --

Resolve merge conflict by selecting theirs

git checkout --theirs file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment