1. Initialize a repository: Git init
2. Clone remote repository: Git clone [email protected]:abc.git
3. Add Remote repository origin, syntax for git remote add [shortname] [url]:git Remote add origin [email protected]:abc.git
4. View remote repository: Git remote-v
5. Add the currently modified file to staging area: Git add
6, if you automatically trace files, including you have been manually deleted, the status of deleted files: Git add-u
7. Submit your changes: Git commit–m "Your comments"
8. Push your updates to the remote server, syntax for git push [remote name] [local branch]:[remote branch]: Git push Origin master
9. View file status: Git status
10. Tracking new files: Git add readme.txt
11. Remove the file from the current tracking list and delete it completely: git rm readme.txt
12, only in staging area delete, keep the file in the current directory, no longer tracking: Git rm–cached readme.txt
13. Renaming files: git mv reademe.txt Readme
14. View commit history: Git log
15. Modify the last commit comment, using –amend parameter: Git commit--amend
16, forget to submit some changes, the following three commands will only get a commit.
- git commit–m "add readme.txt"
- git add Readme_forgotten
- Git commit–amend
17. If you have already used git add, add the modified files A, B to staging area, now you just want to submit a file, do not want to submit B file, should be
git reset HEAD b
18, cancel the modification of the file: Git checkout–-readme.txt
19. Git Merge <branch> # Merge the branch branch into the current branch
20, git merge origin/master--no-ff # do not fast-foward merge, so you can generate a merge commit
21. Create a branch: GIT branch ABC
22. Switch working directory to abc:git chekcout ABC
23. Combine the above commands together to create an ABC branch and switch to Def:git chekcout–b def
24, merge ABC branch, current working directory is def:git merge ABC
25, after the merger is complete, there is no conflict, delete the ABC branch: GIT branch–d ABC
26. Pull away data from remote repository, syntax for git fetch [remote-name]: git fetch
27. Fetch pulls up the latest remote repository data, but does not automatically merge to the current directory: Git pull
28. View Remote Repository information: Git remote show origin
29. Establish a local dev branch to trace the develop branch of the remote repository: git checkout–b dev origin/develop
Common git commands