Dachang git workflow


basic operation

  • git add .
  • git commit -m “fix: xxx”
  • git push

Development workflow

  1. Routine operation

    1. frommaster(formal environment) cut branchfeat-xxx-xxx(abbreviation of current business)
    2. feat-xxx-xxxcodemerge(merge) totext-release(test environment)
    3. After the test environment passes the test, it willfeat-xxx-xxxMerge code intomaster
  2. Merge multiple people and multiple branches into one at a timemaster(commonly known as departure)

    1. After passing the test, frommasterCut branchv2.x.x(version to be released)
    2. takefeat-xxx-xxxfeat-yyy-yyyAnd other branches on the GitHub / gitlab web pageNew merge requestSend the merge request as (MR)(pull request
    3. Wait for the relevant person in chargecode reviewAfter that, we willv2.x.xBranch merge tomaster
  3. When there is a conflict(to prevent conflicts, it is recommended to use the complete process here, which is relatively stable)

    1. frommasterCut branchfeat-xxx-xxx
    2. feat-xxx-xxxCode merge torest-releaseSubmit test
    3. After passing the test, frommasterCut branchv2.x.x
    4. 🚩feat-xxx-xxxmergev2.x.xThe code inside (because master / v2. X.x may have combined the code of other colleagues in the process of development)
    5. At this time, there is conflict resolution, and the local code is best run again to ensure that it is safe
    6. Zaijiangfeat-xxx-xxxadoptNew merge requestCreate a new onepull requestreachv2.x.x
    7. Wait for the relevant person in chargecode reviewlaterMergecode

Command set

  1. 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 modifications

    • git stashStore current change
    • git stash save "save message"Add a note to the current stored event
    • git stash listView the stash storage list
    • git stash popRestore the previously cached working directory and delete this stash
  2. git reset(code fallback)

    • First stepgit log//Get commit information
    • Step 2: copy the commit hash value of the corresponding time of fallback
    • Step 3Git reset -- soft XXXXXXX (commit hash value)
    • --hardDo not save the currently modified,--softYes to save the currently modified
    • Step 4git push -f//Force submission code
  3. git reflog(time shuttle)

    • The code was accidentally backed back. How to fix it?
    • First stepgit reflog//Get all git operations
    • Step twogit reset --hard xxxxxxxx
  4. git cherry-pick

    • When the specified hash point is repaired, the subsequent ones are gone. How to add them?
    • Step 3Git cherry pick XXXXXX (commit hash to be added)
  5. 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 twogit pull upstream
    • Or pull the specified branch (such as master)git pull upstream master
  6. Update remote branch list locally

    • git remote update origin --prune
    • git fetchYes, update all remote branches to the local (if the remote branch is deleted, the local origin will also be deleted after updating)
  7. git merge(consolidation code)

    • Merge branch1 code to current branchgit merge Branch1
  8. git rebase(commit submitted by merging)

    • 7 / 8 operation is best created on the web pageNew merge requestTo 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

git config

  1. View current.gitto configure

    git config user.name
    git config user.email
  2. Set current.gitUser / mailbox

    git config user.name "xxx"
    git config user.email "[email protected]"
  3. Set global.gitto configure

    git config --global user.name "xxx"
    git config --global user.email "[email protected]"
  4. When there are multiple gitlab / GitHub accounts,

    1. For example, gitlab belongs to the company, and the email is also sent by the company, while GitHub email is its own
    2. At this time, it is better not to directly share the global configuration
    3. It is best to configure within a single project
    4. because
    5. Git is based on the mailbox to match the specified user

Coexistence of multiple SSH keys

reference resources:https://www.cnblogs.com/hafiz…

  1. Generate a pair of SSH keys for the company

    ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitlab-rsa
  2. Generate a pair of SSH keys for GitHub

    ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github-rsa
  3. At ~ / Create a new file with the name config in SSH directory (no suffix)vim configCreate).
    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://

#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 Or socket5: //
git config --global http.proxy
git config --global https.proxy

git config --global http.proxy socks5://
git config --global https.proxy socks5://

//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