Tip of the day: git commands to submit code to open source project. CheatSheet
When submitting code to open source project, you need to have the latest code from the main branch. If you don’t, you will get merge conflicts. To avoid this, you need to fetch the latest code from the main branch and rebase your branch on top of it. This is the list of commands you need to run.
Commands
- When your are in your local fork repo, run in console:
1
git checkout main
Note: “main” is a name of branch.
- If you have remote named “upstream” which points to the original repo, run in console:
1
git fetch upstream
- Update your local “main” branch with the latest code from the original repo:
1
git pull --rebase upstream main
- Create a new branch name “updates-myupdate” for your changes:
1
git checkout -b updates-myupdate
- Make your changes and commit them:
1
git commit -m "My update"
- Push your changes to your forked repo:
1
git push origin updates-myupdate
- Create a pull request from your forked repo to the original repo.
1
git pull --rebase upstream main