Steps to be able to make a pull request
We can't push code to a repo if we don't have the permission to do so. This is the reason why we first need to fork the repo and we will push our changes to this forked repo. From there on github we will be able to create a Pull Request.
Step 1: Fork the repo and clone it.
First we need to get a local copy of the repository to which we want to contribute. For that purpose we must have first forked the repository. Once the repo is forked we can copy its url on our account and clone it:
git clone firstname.lastname@example.org:ledahu05/stack-overflow-copy-paste.git
Step 2: Connect the local repository to the original remote on github
When need our local copy to be synced with the project we want to contribute to. We want to ba able to update our codebase to stay up to date. For that purpose we need to connect our local repository with the base repository (I mean here the original repository or upstream repository owned by others).
cd stack-overflow-copy-paste git remote add upstream email@example.com:eggheadio-github/stack-overflow-copy-paste.git
We can now fetch content from the repo to update our local copy:
git fetch upstream
Step 3: Connect our master branch to the original master branch
Right now, our local copy of the master branch is pointing to our personal remote repository, called origin. We want our local copy of master to point to upstream so whenever we pull changes into master it will get the latest changes from the upstream repository
git branch --set-upstream-to=upstream/master master
Now our master branch is tracking the remote upstream/master branch.
Step 4: Create a branch for the code changes
We can create a branch on which we will code the changes:
git checkout -b pr/meaningful_name //add some code git add . && git commit -m "WIP: meaning message"
Step 5: Push the code to our remote
Now we can push our pull request:
git push -u origin pr/meaningful_name //next time git push will be enough
Step 6: Create the Pull Request on github
We can go on github to check the forked repo on our account and look for "Compare & Pull Request" button. If not showing just click the create Pull Request button
Work in progress: rebase if remote is ahead
In some case when pushing new changes to our PR there can be a merge conflict. To solve this we can make a rebase.
git fetch upstream
We are getting a fresh last copy of master and then we apply our changes.
git rebase upstream/master git diff //will show us the files that are having trouble //edit and fix conflicts git add . && git rebase --continue
Using rebase we changed history and by default git will reject our push.
git push -f
Work in progress: cleaning the history
git log --oneline //pick the commit_id git rebase -i commit_id git push -f
End of work
Leave a comment to let know the maintainer that the work is done.