I use Git every day, but I can't remember many commands.
Generally speaking, just remember the following 6 commands for daily use. But skilled use, I'm afraid to remember 60-100 orders.
Here is a list of common Git commands I've compiled. The translated names of some special nouns are as follows.
Workspace: workspace
Index / Stage: staging area
Repository: warehouse area (or local warehouse)
Remote: remote warehouse
1, New code base
# Create a Git code base in the current directory
$ git init
# Create a new directory and initialize it as Git code base
$ git init [project-name]
# Download a project and its entire code history
$ git clone [url]
Two, configuration
Git's settings file is. gitconfig, which can be in the user's home directory (global configuration) or in the project directory (project configuration).
# Show current Git configuration
$ git config --list
# Edit Git profile
$ git config -e [--global]
# Set user information when submitting code
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
3, Add / remove files
# Add specified file to staging area
$ git add [file1] [file2] ...
# Add the specified directory to the staging area, including subdirectories
$ git add [dir]
# Add all files from the current directory to the staging area
$ git add .
# Delete the workspace file and put this deletion in the staging area
$ git rm [file1] [file2] ...
# Stops tracking the specified file, but it remains in the workspace
$ git rm --cached [file]
# Rename the file and put it in the staging area
$ git mv [file-original] [file-renamed]
4, Code submission
# Submit staging area to warehouse area
$ git commit -m [message]
# Submit the specified file of staging area to the warehouse area
$ git commit [file1] [file2] ... -m [message]
# Commit workspace changes since last commit, directly to warehouse
$ git commit -a
# Show all diff information on submit
$ git commit -v
# Replace the last commit with a new commit
# If there is no new change in the code, it is used to overwrite the commit information of the last commit
$ git commit --amend -m [message]
# Redo the last commit and include new changes to the specified file
$ git commit --amend ...
Five, branch
# List all local branches
$ git branch
# List all remote branches
$ git branch -r
# List all local and remote branches
$ git branch -a
# Create a new branch, but still stay in the current branch
$ git branch [branch-name]
# Create a new branch and switch to it
$ git checkout -b [branch]
# Create a new branch pointing to the specified commit
$ git branch [branch] [commit]
# Create a new branch and establish a tracking relationship with the specified remote branch
$ git branch --track [branch] [remote-branch]
# Switch to the specified branch and update the workspace
$ git checkout [branch-name]
# Establish a trace relationship between an existing branch and a specified remote branch
$ git branch --set-upstream [branch] [remote-branch]
# Merge the specified branch to the current branch
$ git merge [branch]
# Select a commit to merge into the current branch
$ git cherry-pick [commit]
# Delete branch
$ git branch -d [branch-name]
# Delete remote branch
$ git push origin --delete
$ git branch -dr
Six, label
# List all tag s
$ git tag
# Create a new tag in the current commit
$ git tag [tag]
# Create a new tag in the specified commit
$ git tag [tag] [commit]
# View tag information
$ git show [tag]
# Submit the specified tag
$ git push [remote] [tag]
# Submit all tag s
$ git push [remote] --tags
# Create a new branch pointing to a tag
$ git checkout -b [branch] [tag]
7, View information
# Show changed documents
$ git status
# Displays the version history of the current branch
$ git log
# Show the commit history and the files that change every commit
$ git log --stat
# Display the version history of a file, including file rename
$ git log --follow [file]
$ git whatchanged [file]
# Display every diff related to the specified file
$ git log -p [file]
# Show who modified the specified file at what time
$ git blame [file]
# Show differences between staging and workspace
$ git diff
# Show differences between staging area and previous commit
$ git diff --cached []
# Shows the difference between the workspace and the latest commit for the current branch
$ git diff HEAD
# Show differences between two submissions
$ git diff [first-branch]...[second-branch]
# Show metadata and content changes for a submission
$ git show [commit]
# Show files that have changed in a submission
$ git show --name-only [commit]
# Displays the contents of a file at the time of a submission
$ git show [commit]:[filename]
# Shows the most recent commits for the current branch
$ git reflog
8, Remote synchronization
# Download all changes to remote warehouse
$ git fetch [remote]
# Show all remote warehouses
$ git remote -v
# Display information about a remote warehouse
$ git remote show [remote]
# Add a new remote warehouse and name it
$ git remote add [shortname] [url]
# Retrieve changes from remote warehouse and merge with local branch
$ git pull [remote] [branch]
# Upload local designated branch to remote warehouse
$ git push [remote] [branch]
# Force the current branch to a remote warehouse, even if there is a conflict
$ git push [remote] --force
# Push all branches to remote warehouse
$ git push [remote] --all
Nine, revocation
# Recover the specified files from the staging area to the workspace
$ git checkout [file]
# Restore the specified file of a commit to the workspace
$ git checkout [commit] [file]
# Recover all files from the previous commit to the workspace
$ git checkout .
# Resets the specified file for the staging area, consistent with the last commit, but the workspace does not change
$ git reset [file]
# Reset staging area and workspace to match last commit
$ git reset --hard
# Resets the pointer of the current branch to the specified commit, and resets the staging area, but the workspace does not change
$ git reset [commit]
# Reset the HEAD of the current branch to the specified commit, and reset the staging area and workspace at the same time, consistent with the specified commit
$ git reset --hard [commit]
# Reset the current HEAD to the specified commit, but leave the staging area and workspace unchanged
$ git reset --keep [commit]
# Create a new commit to undo the specified commit
# All changes in the latter are offset by the former and applied to the current branch
$ git revert [commit]
Ten, others
# Generate a compressed package for publishing
$ git archive
# Back up the contents of the current workspace
$ git stash
# Read the last saved content from Git stack and recover the relevant content of the workspace
$ git stash pop
#Show all backups in Git stack
$ git stash list
#Empty Git stack
$ git stash clear
Write at the end: welcome to leave a message to discuss, pay more attention and keep updating!!!