Six months of internship , It summarizes some commonly used github command ：
The way our company uses is to put the company library first Fork Come down , After modifying your local library push To your own remote library , And then submit PR, After others passed, they merged . And you don't usually have to merge, While using rebase send git The tree looks like a straight line （ I have a shallow and thorough understanding of ）, The code is developed with VSCode, There's also management on it git Tools for （ This works well on company computers ,but not mine）
These blogs really helped me a lot , Thank you very much .
technological process ：
- Application account , Add public key . Our company uses ssh, This application authority Use SSH Connect to GitHub. After a long time , I'm not going to repeat it all here （ Actually, I forgot ）.
- Detailed process ：fork -> clone -> Create a branch -> Modify the code -> Submit -> Submit PR
A few commands that I often use
- git add .
- git commit
- git status
- git fetch upstream
- git rebase upstream master
- git push origin master -f
- git rebase -i HEAD~n
- git reset
- git checkout -b branchName
- git branch -d branchName
A few commands that are not commonly used
- git diff See Diff command
VScode Self contained or downloadable tools
The following operations have not gone through fork Of , And in master The process of direct operation under the branch . If you want to switch branches , It can be executed ：git checkout -b checkName.
PS： I was at the beginning master Under the branch , Later, we need to PR It's a lot more , I used the branching method slowly . It's so convenient . and VScode It's easy to operate with your own tools
Get to the point
Change the file from the workspace workspace Add to the staging area stash Inside ,commit The necessary work before .git diff Command to see the difference between the two （ I don't use it very often ）
git add . ： Add all changed files to stage Inside
git add fileName
Add the files in the cache to the repository ,git diff head You can see the difference between the two , It is best to git commit -m "commit Information ", If direct git commit There may be errors , in addition commit message standard
And then I executed git add. Submit the remaining two documents together .
perform git log View submission records
Connect to the remote library
git remote -v You can see which library is remotely connected
git push origin master // Submit your own commit Remote submission to your own library master Under branch .master You can also change it to another branch name
Then you can submit PR 了
Commonly used in
1. Submit code multiple times , But in the end, only one commit Of . Reference resources rabase Merge multiple commit
2. Submit pr Before finishing git Trees . Every time you submit, you need to guarantee that rebase upstream/master after （ Merge the remote library's with your own ） There is no conflict , But this merger is different from merge,rebase It's like connecting to your own remote branch master after , So the whole commit tree is a straight line .
I am here 1.txt It was modified in ： This can be done in the following way commit
If you want to merge several commit, For example, the second submission and the first modification merge , It can be executed
git rebase -i HEAD~2