Git common process
-
For new projects, initialize your project in your project directory. If it is (existing project) subsequent function development/code change, please ignore this step .
cd <项目目录> git init
-
Checkout (checkout) a new feature or bug fix (feature/bug-fix) branch.
git checkout -b <分支名称>
-
Added code changes.
git add git commit -a
git commit -a
An editor will be launched independently to edit your description information, so that you can focus on writing these notes. -
Keep in sync with the remote (develop branch) so that (the local develop branch) gets the latest changes.
git checkout develop git pull
Keeping updated gives you a chance to resolve conflicts on your machine when you do a (later) rebase. This is better than (doing the next rebase operation without syncing the update and) making a merge request that conflicts with the remote repository.
-
(Switch to feature branch and) update your feature branch by interactively rebasing the latest code commit from your develop branch.
git checkout <branchname> git rebase -i --autosquash develop
You can
--autosquash
squash all commits into a single commit with . No one wants (sees)develop
a single feature development in a branch taking up so much commit history. -
Skip this step if there are no conflicts, if you have conflicts, you need to resolve them and continue with the rebase operation.
git add <file1> <file2> ... git rebase --continue
-
Push your (feature) branch. Rebasing changes the commit history, so you must use
-f
force push to remote (feature) branch. If other people are co-developing with you on that branch, use a less destructive--force-with-lease
parameter.git push -f
When you rebase, you change the commit history of the feature branch. This causes Git to reject normal ones
git push
. Then, you can only use-f
the or--force
parameter. -
Submit a pull request.
-
Pull Requests are accepted, merged and closed by colleagues responsible for code reviews.
-
Remember to delete your local branch if you are done developing.
git branch -d <分支>