GitHub is a platform that enables collaboration. It brings people together to work on projects and documentation from anywhere in the world. When I was new to GitHub, resolving errors was a painstaking process that sometimes resulted in me needing help from colleagues. However, whenever I ask for help, I always make sure to learn the rationale behind the solution to make sure that I can use it to help others in the future.
Basic Steps
The following is the basic approach that I follow on a day-to-day basis when working with GitHub.
- Navigate to the Git branch that you want to use.
Format:
git checkout <branch-name>
Example:
git checkout master-1 - Update your local Git branch before making any changes.
Format:
git fetch upstream
git merge upstream/<upstream-branch>
Example:
git fetch upstream
git merge upstream/master - Make the required changes.
- Save the changes locally.
Format:
git add <file path or folder path>
git commit -m “<commit message>”
Example:
Let’s assume that you are updating some content related to the pages in the create-streaming-api folder.
git add en/docs/design/create-api/create-streaming-api/
git commit -m "Revamping the streaming API content" - Update your local Git branch after adding local changes.
Format:
git fetch upstream
git rebase upstream/<upstream-branch>
Example:
git fetch upstream
git rebase upstream/master
NOTE: You can sometimes face some errors when executing the rebase command.- If your local branch is not too outdated, then it will be very straightforward to resolve these errors.
- If your local branch is very outdated, it will be more complicated to resolve these errors. Therefore, skip the rest of the instructions and move to the Workaround to expedite the troubleshooting process.
- Push your changes to your remote repository.
Format:
git push <your-remote-branch> <local-branch-name>
Example:
git push Mariangela master-1 - Create a pull request (PR) to send your fix to the upstream GitHub repository.
Workaround
The basic logic for this approach is that you will not face major rebasing issues if your local branch is up-to-date with the upstream branch. Therefore, to get out of this mess you can simply create a brand new branch and reapply your changes in that branch as follows:
NOTE: It is assumed that you moved to these instructions after step 5 in the Basic Steps.
- Abort the GitHub rebase process.
git rebase --abort - Note down the commit IDs that correspond to the new changes you worked on in the previous GitHub branch.
git log - Create and move to a new branch that corresponds to the same upstream branch.
Format:
git checkout upstream/<upstream-branch> -b <new-branch>
Example:
git checkout upstream/master -b master-2 - Update your local GitHub branch before adding local changes.
Format:
git fetch upstream
git merge upstream/<upstream-branch>
Example:
git fetch upstream
git merge upstream/master - Apply your changes one by one to this branch.
Make sure to apply the commits in the order in which you originally added them.
Format:
git cherry-pick <commit-ID>
Example:
git cherry-pick f1c0dc890d6a0d92e181fab84deedb777e398ccf - Resolve any merge conflicts locally.
- Update your local Git branch after adding all the local changes.
Format:
git fetch upstream
git rebase upstream/<upstream-branch>
Example:
git fetch upstream
git rebase upstream/master - Push your changes to your remote repository.
Format:
git push <your-remote-branch> <local-branch-name>
Example:
git push Mariangela master-2 - Create a pull request (PR) to send your fix to the upstream Git repository.
Acknowledgments
A huge thank you goes out to Bhathiya Jayasekara for introducing me to the above mentioned workaround.
Comments
Post a Comment