Git common command summary

Time:2021-6-11

Next, take from GitHub as a remote warehouse as an example. Gitee only needs to replace the corresponding warehouse link. For git related teaching, please refer to teacher Liao Xuefeng’s git tutorial, which is not introduced here. Of course, the following command line is just for you to know how to operate git without graphical tools. I think it’s necessary to know, and it’s also helpful to understand git principle

  1. Configure Git
    Git user name

    git config --global user.name "Your Name"

    mailbox

    git config --global user.email "[email protected]"

    Git display color

    git config --global color.ui true
  2. initialization

    mkdir project
    cd project
    git init
  3. Add file and submit code(git commitWe need to do it firstgit addcommitSubmit onlyTemporary storage areaContent of

    Git add readme.md (file name)
    #Git add - F readme.md (- F is mandatory and can submit the file configured in. Gitignore)
    Git commit - M "submit remarks"
  4. View current warehouse status

    git status
  5. Changes in the reference document

    Git diff readme.md (file name)
  6. View git log

    git log
  7. Version fallback to before the nth version

    git reset --hard HEAD~N
  8. Version fallback (switch) to the specified version (GIT, unique hexadecimal ID for each submission,git logperhapsgit reflog(record the information submitted one at a time) can be viewed)

    Git reset -- hard e475afc93c209a690c39c13a46716e8fa000c366
  9. Undo the modification (undo to the last time)git addorgit commitPrevious status)

    Git checkout -- readme.md (file name)
  10. Undo the modification of the staging area(git commit(before)

    Git reset head readme.md (file name)
  11. Delete the file (confirm that you need to delete it)git commitIf it is deleted by mistake, it can be usedGit checkout -- file name)

    Git RM readme.md (file name)
  12. View remote warehouse connection information (fetch, push)

    git remote -v
  13. Associated remote warehouse

    git remote add origin [email protected]:username/xxxx.git
  14. Push to remote library (first push)masterBranch)

    git push -u origin master
  15. Push to remote library

    Git push origin branch name
  16. Clone code

    git clone https://github.com/username/xxxx.git

    or

    git clone [email protected]:username/xxxx.git
  17. Clone the specified branch code

    Git clone - B branch name https://github.com/username/xxxx.git
  18. Create branch

    Git branch name
  19. Switch branches
    Old version

    Git checkout branch name

    New version

    Git switch branch name
  20. Create branches and switch
    Old version

    Git checkout - B branch name

    New version

    Git switch - C branch name
  21. View branches

    git branch
  22. View all branches (local + Remote), the remote branch will be marked in red, and the current branch will be marked with one*(No.)

    git branch -a
  23. Merge a branch to the current branch. If there is a conflict, you will be prompted to modify it manually before submitting,git mergeDefault tofast forwardpattern
    fast forwardpattern

    Git merge other branch names

    DisableFast forwardMode(--no-ff) recommend

    Git merge -- no-ff - M "submit remarks" other branch names

    usegit log --graph --pretty=oneline --abbrev-commitCommand to see the branch merge diagram

  24. Delete branch

    Git branch - D branch name

    Forcibly delete branch

    Git branch - D branch name
  25. Save workspace

    git stash
  26. View saved workspaces

    git stash list
  27. Restore from saved workspace

    git stash apply 

    If there are multiple saved workspaces (n is the serial number, starting from 0)

    git stash apply [email protected]{n} 
  28. Delete a saved workspace

    git stash drop

    If there are multiple saved workspaces (n is the serial number, starting from 0)

    git stash drop [email protected]{n} 
  29. Restore and delete a saved workspace from a saved workspace

    git stash pop

    If there are multiple saved workspaces (n is the serial number, starting from 0)

    git stash pop [email protected]{n} 
  30. Apply commits on other branches to the current branch

    Number of GIT cherry pick commit
  31. Grab code

    git pull
  32. Associate a local branch with a remote branch

    Git branch -- set upstream to branch name origin / branch name
  33. The local unpushed fork submission history is sorted into straight lines;

    git rebase

    The purpose of rebase is to make it easier for us to see changes in historical submissions, because forked submissions require tripartite comparison.

  34. Tagging

    Git tag v1.0 commit ID
    Git tag - a v1.0 - m the ID of the "submit remarks" commit (if not, the subsequent commit will be tagged)
  35. View all tags

    git tag
  36. View label information

    git show v1.0
  37. Delete local label

    git tag -d v0.1
  38. Delete remote label

    git push origin :refs/tags/v1.0
  39. Push a label to remote

    git push origin v1.0
  40. Push all tags that have not been pushed

    git push origin --tags
  41. The same set of code is associated with multiple remote libraries (for example, associating GitHub and gitee at the same time)
    Remote library associated with GitHub

    git remote add github [email protected]:username/xxxx.git

    Remote library associated with gitee

    git remote add gitee [email protected]:username/xxxx.git

    Push GitHub

    git push github master

    Push gitee

    git push gitee master
  42. see.gitignoreWhich rule is wrong in the file

    Git check ignore - V file name
  43. Set command alias
    git status => git st

    git config --global alias.st status

    git reset HEAD file => git unstage

    git config --global alias.unstage 'reset HEAD'

    git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit => git lg

    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

So much for the time being

This article uses openwrite to write

Recommended Today

The road of high salary, a more complete summary of MySQL high performance optimization in history

preface MySQL for many linux practitioners, is a very difficult problem, most of the cases are because of the database problems and processing ideas are not clear. Before the optimization of MySQL, we must understand the query process of MySQL. In fact, a lot of query optimization work is to follow some principles so that […]