1. Configure the name and email address
-
- When changing the account and changing the code, the previous identity information is displayed if it is not reconfigured
-
- –global Indicates the global configuration. You do not need to add this attribute
Git config --global user.name git config --global user.email Specifies the email addressCopy the code
2. Default branch name
-
- Using Git init creates a branch named master by default
-
- Set main as the default branch name
Git config --global init.defaultBranch [main]Copy the code
Check your current Git configuration
-
- Self-operated display (identity, branch, status….)
git config --list
Copy the code
4. Obtain command help
git help config
Copy the code
5. Git initialization of the project
git init
Copy the code
6. Submit files, temporarily save files and perform other operations
Documents submitted:
git add *.c
git add LINCENSE
git commit -m "Initial project version"
Copy the code
7. Get an existing repository
-
- The default copied target name is the name of the project
-
- If a new directory is specified, add the name of the new directory after the url
Git clone address [url] | | new directory [name]Copy the code
8. Check the file status
- Untracked and tracked files
git status
Copy the code
9. Ignore files
Description to Be Added
10. View staged and unstaged changes
git diff
Copy the code
11. Commit changes
-
- -m indicates the master branch
-
- -a: Skip the dock (skip git add section)
Git commit -mCopy the code
12. Delete files
-
- Forcibly delete -f
git rm
Copy the code
13, move files | | renaming files
git mv file_from file_to
Copy the code
14. Record information
-
- Git log –stat abbreviation statistics
-
- git log –pretty = [oneline || short || full || fuller || format]
git log
Copy the code
15, cancellation
-
- Recommit, temporary other operations: git commit –amend
-
- Git restore HEAD
-
- Unmodify the modified file: git checkout — filename
16. View the remote server
- Not very often, need to use, learn by yourself
git remote
Copy the code
17, mark
git tag
Copy the code
18, branch
-
- Create a new branch
Git branch Specifies the branch nameCopy the code
-
- Switch branch
Git Checkout branch nameCopy the code
-
- Create a new branch and switch
Git checkbox -b branch nameCopy the code
-
- Merging branches
Git checkbox master 2. Merge Git merge other-branch 3. Delete a branch: git branch -d other-branchCopy the code
Git branch after 2.23
** Git checkbox becomes git switch **
2. Create and switch git switch -c to create a new branch. 3. Return to the previous branch: git switch -Copy the code