When you’re trying to edit the codes, switch to a new branch in advance.
1
git checkout -b my-featyre #my-feature is the name of the branch
3*. See the changes you made
Optionally, you can choose to se the changes you made(Strongly suggested).
1
git diff
4. Commit those changes to the local git
1 2 3
git add <changed_file> #or just use "git add ." git commit #or just use "git commit -m 'XXX'" git push origin my-feature
5*. Update main branch in local git
When you find that remote main branch updates before you push, do the following steps to sync the updates and figure out if your commits could still run.
1 2 3 4 5
git checkout main #switch to the main branch git pull origin master #update local main branch git checkout my-feature #return to my-feature branch git rebase main #update original codes in advance, then add changes in your commits #you need to choose which you want to reserve when the main branch updates and your commits conflict
6.Push your feature branch
1
git push -f origin my-feature
7.Pull request
Submit pull request in GitHub, and wait the owner to do squash and merge.
8.Delete feature branch
Once you got a successful pr, you can just delete your feature branch on GitHub. For the local feature branch, just do the following steps.
1 2 3
git checkout main #switch to the main branch git branch -D my-feature #delete your local feature branch git pull origin master #sync the latest updates