basic operation
- git add .
- git commit -m “fix: xxx”
- git push
Development workflow
-
Routine operation
-
Merge multiple people and multiple branches into one at a time
master
(commonly known as departure)- After passing the test, from
master
Cut branchv2.x.x
(version to be released) - take
feat-xxx-xxx
、feat-yyy-yyy
And other branches on the GitHub / gitlab web pageNew merge request
Send the merge request as (MR)(pull request
) - Wait for the relevant person in charge
code review
After that, we willv2.x.x
Branch merge tomaster
- After passing the test, from
-
When there is a conflict(to prevent conflicts, it is recommended to use the complete process here, which is relatively stable)
- from
master
Cut branchfeat-xxx-xxx
feat-xxx-xxx
Code merge torest-release
Submit test- After passing the test, from
master
Cut branchv2.x.x
- 🚩
feat-xxx-xxx
mergev2.x.x
The code inside (because master / v2. X.x may have combined the code of other colleagues in the process of development) - At this time, there is conflict resolution, and the local code is best run again to ensure that it is safe
- Zaijiang
feat-xxx-xxx
adoptNew merge request
Create a new onepull request
reachv2.x.x
- Wait for the relevant person in charge
code review
laterMerge
code
- from
Command set
-
git stash
(code temporary storage, non commit)
It is generally used when you need to cut branches and don’t want to commit when you have code modificationsgit stash
Store current changegit stash save "save message"
Add a note to the current stored eventgit stash list
View the stash storage listgit stash pop
Restore the previously cached working directory and delete this stash
-
git reset
(code fallback)- First step
git log
//Get commit information - Step 2: copy the commit hash value of the corresponding time of fallback
- Step 3
Git reset -- soft XXXXXXX (commit hash value)
--hard
Do not save the currently modified,--soft
Yes to save the currently modified- Step 4
git push -f
//Force submission code
- First step
-
git reflog
(time shuttle)- The code was accidentally backed back. How to fix it?
- First step
git reflog
//Get all git operations - Step two
git reset --hard xxxxxxxx
-
git cherry-pick
- When the specified hash point is repaired, the subsequent ones are gone. How to add them?
- Step 3
Git cherry pick XXXXXX (commit hash to be added)
-
Fork library fetches upstream code
- The first step is to add the remote link of upstream warehouse
git remote add upstream https://github.com/xx/repo
- Step two
git pull upstream
- Or pull the specified branch (such as master)
git pull upstream master
-
Update remote branch list locally
git remote update origin --prune
git fetch
Yes, update all remote branches to the local (if the remote branch is deleted, the local origin will also be deleted after updating)
-
git merge
(consolidation code)- Merge branch1 code to current branch
git merge Branch1
- Merge branch1 code to current branch
-
git rebase
(commit submitted by merging)- 7 / 8 operation is best created on the web page
New merge request
To operate - The general step is merge, and then there is an option next to it, whether to rebase
- If it is checked, all the commits from your merge will be merged into one commit
- 7 / 8 operation is best created on the web page
git config
-
View current
.git
to configuregit config user.name git config user.email
-
Set current
.git
User / mailboxgit config user.name "xxx" git config user.email "[email protected]"
-
Set global
.git
to configuregit config --global user.name "xxx" git config --global user.email "[email protected]"
-
When there are multiple gitlab / GitHub accounts,
- For example, gitlab belongs to the company, and the email is also sent by the company, while GitHub email is its own
- At this time, it is better not to directly share the global configuration
- It is best to configure within a single project
- because
- Git is based on the mailbox to match the specified user
Coexistence of multiple SSH keys
reference resources:https://www.cnblogs.com/hafiz…
-
Generate a pair of SSH keys for the company
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitlab-rsa
-
Generate a pair of SSH keys for GitHub
ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github-rsa
-
At ~ / Create a new file with the name config in SSH directory (no suffix)
vim config
Create).
It is used to configure multiple different hosts to use different SSH keys. The contents are as follows:# gitlab Host gitlab.com HostName gitlab.com PreferredAuthentications publickey IdentityFile ~/.ssh/gitlab-rsa # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github-rsa
Git agent for telecommuting
#Only for GitHub com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
#Cancel agent
git config --global --unset http.https://github.com.proxy
//View current proxy settings
git config --global http.proxy
git config --global https.proxy
//Set current proxy to http://127.0.0.1:1080 Or socket5: // 127.0.0.1:1080
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
//Delete proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
The big factory is really tired and does the same work, but it is more refined. Just after the release day, there is only one, one or one person’s time to recharge