50 commonly used Git commands

  1. git init - Initialize a new Git repository.
  2. git clone <url> - Clone (download) a remote Git repository locally.
  3. git add <file> - Add files to the staging area.
  4. git commit -m <message> - Commit changes to the staging area and add commit messages.
  5. git status - View the status of the working tree and staging area.
  6. git diff - See the differences between the current file and the last commit.
  7. git branch - List all branches, the current branch will be marked with an asterisk.
  8. git checkout <branch> - Switch to the specified branch.
  9. git merge <branch> - Merge changes from the specified branch into the current branch.
  10. git remote add <name> <url> - Add the alias and URL of the remote repository.
  11. git fetch <remote> - Get latest references and objects from remote repository.
  12. git pull <remote> <branch> - Get latest changes from remote repository and merge into current branch.
  13. git push <remote> <branch> - Push changes from the current branch to the remote repository.
  14. git log - View commit log.
  15. git reset <commit> - Roll back to the specified commit.
  16. git stash - Saves current changes and resets the working tree to the state of the last commit.
  17. git tag <tagname> - Create a new label.
  18. git cherry-pick <commit> - Select a commit and apply it to the current branch.
  19. git rebase <branch> - Reapply changes from the current branch to the specified branch.
  20. git remote -v - Show details of remote repository.
  21. git show <commit> - Show commit details and changes.
  22. git rm <file> - Delete files from Git.
  23. git mv <old> <new> - Rename or move files.
  24. git blame <file> - Show file modification history line by line.
  25. git config --global user.name <name> - Configure global username.
  26. git config --global user.email <email> - Configure global user mailbox.
  27. git cherry-pick --continue - Continue the cherry-pick operation where it was interrupted.
  28. git reflog - View the ref log, including deleted branches and reset operations.
  29. git revert <commit> - Undo the changes of the specified commit.
  30. git clean -n - Shows untracked files that will be deleted.
  31. git bisect start - Start a binary search (used to locate the commit that introduced the bug).
  32. git bisect good - Mark the current commit as "good" (no errors).
  33. git bisect bad - Mark the current commit as "bad" (has bugs).
  34. git bisect reset - Terminate binary search and reset HEAD to initial state.
  35. git log --graph - Display commit history graphically.
  36. git blame -L <start>,<end> <file> - Display the modification history of the specified range of the file line by line.
  37. git stash apply - Apply recently saved stash and retain stash contents.
  38. git stash drop - Discard recently saved stash.
  39. git tag -a <tagname> -m <message> - Create a label with annotation.
  40. git checkout -b <new-branch> - Create a new branch and switch to it.
  41. git reset --hard <commit> - Resets the current branch to the specified commit and forces an update of the working tree.
  42. git push <remote> :<branch> - Delete the specified branch on the remote repository.
  43. git grep <pattern> - Search version history for files and content matching patterns.
  44. git log --author=<author> - View posts submitted by a specific author.
  45. git diff <commit1>..<commit2> - View differences between two commits.
  46. git revert --no-commit <commit> - Undoes the changes of the specified commit, but does not automatically create a new commit.
  47. git bisect next - Switch to the next commit during binary search.
  48. git rebase -i <commit> - Interactively rebase commits after the specified commit.
  49. git config --global core.editor <editor> - Configure the text editor used globally.
  50. git push --tags - Push all tags to remote repository.
  51. git log --grep=<pattern> - View logs for commit messages containing specific patterns.

Guess you like

Origin blog.csdn.net/qq_53873381/article/details/132175067