1. Basic understanding of git
Git is an open source distributed version control system; in simple terms, it is a version control tool, code hosting tool
Two, git code management command
- Clone project code: git clone https://gitee.com/***/*****.git
- Associated remote warehouse: git remote add origin https://gitee.com/***/*****.git
- Create a branch: git branch dev (dev is the branch name)
- Delete branch: git branch -d dev (dev is the branch name)
- Switch branch: git checkout dev or git switch dev ( error: 'switch' is not a git command. See 'git --help', you need to upgrade the git version)
-
Create and switch branches at the same time: git checkout -b dev or git switch -c dev
-
Merge branch: git merge dev (dev is the branch name) --- used to merge the specified branch into the current branch
3. The operation process of git management in actual work
(1) Take over the project for the first time: the company will provide an online warehouse address
- If it is an internal server, the project manager will give the user name and password
- If it is a third-party warehouse, like gitee, coding, you need to register and log in yourself, and the project manager needs to invite you to join this project
(2) Project operation process
- Find the project and clone the code git clone https://gitee.com/***/*****.git
- Switch to the branch you develop: git checkout dev (or use vscode visual operation), develop projects, and write code
- After the code is developed (that is, before get off work), submit the code. Considering that multiple people are developing on the same branch, stash (hide) before submitting the code
- Hide code written by yourself: git stash
- Pull the latest code: git pull
- Release the hidden code: git stash pop
- Add code to the staging area: git add .
- Add from the staging area to the history area: git commit -m "created by dev" (comment information created by dev for writing code)
- Upload to the online warehouse: git push
- Merge into the master branch
- Switch to the master branch first: git checkout master
- Pull the latest code from master: git pull
- Merge the dev branch into master: git merge dev
- Submit the merged code to git: git push