Ready to work
=========
0. Clone a remote codestore
git clone ...
1. Create a work branch locally
git checkout -b work
daily work
===========
0. Make various modifications in the local work branch, and submit them after the modification.
git commit
1. Go to the trunk and catch the latest changes of others to the local master
git checkout master
git pull origin master
2. Modification of the rebase trunk on the work branch
git checkout work
git rebase master # This step may require conflict resolution.
2.1. (Optional) If the xxx file conflicts at this time, git will automatically create a temporary branch locally. You need to edit the conflicting file under this branch to resolve the conflict:
Edit xxx file
git add xxx
git rebase --continue # Continue to rebase, if successful, it will return to the work branch
or
git rebase --abort # Go back to the state before rebase, return to the work branch
2.2. (Optional) If you want to back up the local work branch to the server, you can choose to upload it at this point in time
git push origin work
3. Merge the modifications of the work branch on the trunk. (since we've done a rebase, there shouldn't be any conflicts here)
git checkout master
git merge work
4. Push the local master to the server, so that others can see the results of your work
git push origin master
As long as you follow this order, these are basically all the git commands you need to use every day, and you won't encounter any strange troubles. And the history of the master will remain linear, and there will be no multiple history.
Note: This is just our recommended workflow. Because git is more flexible and supports many different workflows, it can't stop you from not following this process. So, be sure to figure out what you're doing before doing it later.
When using git, keep in mind one simple principle:
When you modify a function under your own branch and want to merge the code back to the trunk, please execute on the trunk: git merge branch name
When you are working under your own branch and others have made some changes on the trunk, and you want to merge these changes into your own branch, please execute under your own branch: git rebase master (do not execute git merge master)
In this way, the commit history of the code can be made cleaner, especially when multiple people develop, the history of the code is linear