Daily operation
- Add files to the repository
git add Copy the code
- Add a single file to the repository
git add test.text Copy the code
- A file with a suffix added
git add *.html Copy the code
- Commit the repository file
Git commit -m RemarksCopy the code
- Into the warehouse
git push Copy the code
- Pull files from the warehouse
git pull Copy the code
Viewing Historical Status
- The current state
git status Copy the code
- Viewing Historical Records
git log Copy the code
Undo modify
- Undo any changes that have not yet been committed
git checkout head . Copy the code
- Undo a single suffix file that has not yet been committed
Git checkout head *Copy the code
branch
- See the branch
# View all local branches git branch # view all remote branches git branch -r View all local and remote branches git branch -a Copy the code
- The new branch
Git Branch Branch nameCreate a new branch based on the remote branch and switch to itGit checkout -b origin/ remote branchCopy the code
- Switch branch
Git Checkout branch nameCopy the code
- Delete the branch
# delete branch (this command will fail to delete branches if they are not merged)Git branch -d Specifies the branch name# delete branchGit branch -d Specifies the branch name# delete remote branches that no longer exist git remote prune origin Copy the code
- Merging branches
# If a conflict occurs, it will not be committed automaticallyGit merge specifies the branch nameCopy the code
- Rename branches
# branches with the same name will not be overwrittenGit branch -m Original branch name New branch name# overwrites branches of the same nameGit branch -m Original branch name New branch nameCopy the code
- Establishes a trace relationship between an existing branch and a specified remote branch
Git branch --set-upstream Name Name of the remote branchCopy the code
cloning
- Cloning project
git cloneThe SSH or HTTP address of the project# ssh git clone [email protected]:songxiaoQ/test.git # https git clone https://github.com/songxiaoQ/test.git Copy the code
- Clone the code for the specified branch
git clone-b Branch name SSH or HTTP address of the projectCopy the code
Basic Settings (initialization)
- Configure git accounts globally
git config --global user.name "Your Name" git config --global user.email "[email protected]" Copy the code
- Query a configured Git account
git config --global user.name git config --global user.email Copy the code
- Example Remove a global configuration account
git config --global --unset user.name git config --global --unset user.email Copy the code
- Generating an SSH Public Key
ssh-keygen -t rsa -C "[email protected]" Copy the code
- Initialize the Git repository
git init Copy the code
Other commands
-
Git is case-sensitive. Git on Windows is case insensitive by default
git config core.ignorecase false Copy the code