1 create a repository 2 $mkdir learngit 3 $cd learngit 4 $pwd (view the current repository directory) 5 6 turn the directory into a management repository 7 $git init 8 9 commit files to the repository 10 $git add readme.txt 11 $git commit -m " worote a readme file " 12 13 Add a file Step 14 The first step is to add the file with $git add 15 The second step is to submit the changes with $git commit 16 The staging area is stored 17 The core of git management is #management modification #Not managing files 18 19 Keep track of workspace status 20 $git status 21 22 View the modified content 23 $git diff file_name 24 25 View the history 26 $git log 27 $git log --pretty= oneline 28 29 Return the current version to the previous version 30 $git reset --hard HEAD^ 31 32 View the current version Version 33 $cat file_name 34 35 Go back to the latest version 36 $git reset -- hard commit ID 37 38 View command log 39 $git reflog 40 41 Drop the workspace to modify 42 $git checkout -- file_name 43 44 Delete the file 45 $rm file_name 46 $git rm file_name 47 48 Repository version replaces workspace version 49 $git checkout -- file_name 50 51 github add remote repository 52 $git remote add origin [email protected]: github ID/ learngit.git 53 (origin remote library name) 54 55 Push all the contents of the local library to the remote library (the first push) 56 $git push - u origin master 57 58 After the local commit, you can pass the command 59 $git push origin master (the local master branch The latest push to github) 60 61 Remote clone to local library 62 $git clone [email protected]:Dimoango/ name (requires clone library name).git 63 $cd name 64 $ls 65 66 Create and merge branches 67 Create dev branch, switch to dev branch 68 $git checkout -b dev 69 The git checkout command plus -d parameter means create and switch 70 is equivalent to git branch dev 71 git checkout dev 72 View branch 73 $git branch 74 75 The branch work is completed and switch back to master 76 $git checkout master 77 78 View remote library information, use git remote - v; 79 80 If the newly created branch is not pushed to the remote, it will be sent to others is just invisible; 81 82 push branch from local, use git push origin branch -name, if the push fails, first use git pull to grab the new remote commit; 83 84 Create a branch corresponding to the remote branch locally, use git checkout -b branch-name origin/branch-name , the names of the local and remote branches are the most Good consistency; 85 86 Establish the association between the local branch and the remote branch, use git branch --set-upstream branch-name origin/branch- name; 87 88 Grab the branch from the remote, use git pull, if there is a conflict, deal with it first conflict. 89 Merge the dev branch work to the master branch 90 $git merge dev 91 92 Delete the dev branch 93 $git branch -d dev 94 95 The git log --graph command can see the branch merge graph. 96 97 delete issue- 101 branch 98 $ git checkout master 99$ git merge --no-ff -m " merged bug fix 101 " issue-101 100 101 save the site 102 git stash the work site 103 git stash pop again, go back to the work site 104 105 discard a branch that has not been merged, It can be forcibly deleted by git branch -D <name> . 106 107 View the remote library 108 $git remote - v 109 110 Switch to the branch that needs to be tagged 111 git tag <name> to type a new tag 112 You can use the command git tag to view all tags: 113 114 Command git tag <name > Used to create a new tag, the default is HEAD, you can also specify a commit id; 115 116 git tag -a <tagname> -m "blablabla... " Can specify tag information; 117 118 git tag -s <tagname> -m " blablabla... " Can sign tags with PGP; 119 120 Command git tag can view all tags.