GitHub Common commands

Source: Internet
Author: User

Create a version Library

Mkdir Baidu
CD Baidu
Git init

 


SSH
Ssh-keygen-T-RSA-c "[email protected]"
(In new ssh on GitHub, the content is id_rsa.pub)

 

 

Add remote database
(Create a git repository on GitHub and select reamde. md)
Git remote add origin [email protected]: taylorapril/Baidu. Git
Git push-u origin master
(Error)
Git pull -- rebase origin master
Git push-u origin master
Git push origin master

 

 

Submit (file name read.txt)
Git add read.txt
(GIT Add. For all files .)
Git commit-M "description text"
Git push

 


Version rollback
(View the most recent submitted log)
Git log -- prtty = oneline
(Rollback version count: Head ^ previous version, head ~ 100 and 100 versions)
Git reset -- hard head ^
(Rollback version number: the rollback version commit ID is 3628df)
Git reset -- hard 3628df
(To restore: Use the Command record to retrieve the commit ID rollback)
Git reflog

 


Undo Modification

---> Git add files git commit
Working directory -------------- stage ------------- history
<--- Git checkout -- files git reset -- files

 

 

Delete file (read.txt)
Rm read.txt
(Delete from version Library)
Git RM read.txt
Git commit-M "delete"
(Delete error)
Git checkout -- read.txt

 

 

Branch (branch name Dev)
Create branch: git branch Dev
Switch branch: git checkout Dev
Create + switch branch: git checkout-B Dev
View Current branch: git Branch
Switch back to master branch: git checkout master
Merge the specified branch to the current branch: git merge Dev
(Fast-forward fast forward mode)
Delete branch: git branch-D Dev

 


Resolve Conflicts (branch name FEA)
Cause of conflict: both master and Dev increase at the same time.
Git checkout-B FEA
(Modify creating a new branch is quick and simple .)
Git add read.txt
Git commit-M "FEA"
Git checkout master
(Modify creating a new branch is quick & simple .)
Git addread.txt
Git commit-M "master"
(In this case, the master and FEA point to a branch respectively)
Git merge FEA
(For details about merging errors, see git status and CAT read.txt)
(Modify the text content of read.txt creating a new branch is quick and simple .)
Git add read.txt
Git commit-m "conf"
(Now master and FEA point to the same person, git log can view the merger)
Git branch-D FEA

 


Branch Management Policy (-- no-ff) (branch name Dev file name read.txt)
Git checkout-B Dev
Git add read.txt
Git commit-M "Dev"
Git checkout master
(Note that the next parameter -- no-FF indicates that fast forward is disabled)
(Fast Forward merge does not show that it has been merged, but the -- no-FF parameter merged has branches. Negative shows that it has been merged)
Git merge -- no-FF-M "merge with -- no-FF" Dev
(View the branch history git log -- graph -- pretty = oneline -- abbrev-commit)

 


Bug branch (the bugg branch is the branch to solve the bug)
Idea: when there is still a job at hand, first commit the GIT stash at the job site (to avoid fixing the bug and commit it together for the finished work), then fix the bug and submit it, use git stash pop to display the original work in the workspace.
(Check the status of git status)
Git stash
Git checkout-B bugg
(After modifying the bug)
Git add bugg.txt
Git commit-M "Fixed bug"
Git checkout master
Git merge -- no-FF-M "merge bug" bugg
Git branch-D bugg
(Return to Dev to continue working)
Git checkout Dev
(View git status in the workspace)
(Use git stash list to view details)
Git stash list
(The first method of recovery: Restore and delete the stash content at the same time)
Git stash pop
(Method 2: Restore without deleting stash content)
Git stash apply
(If you use the second method to delete stash, use git stash drop)
(If multiple files are stash, use git stash apply [email protected] {0} to restore the specified stash)

 


Feature Branch (Dev Branch)
(Force Delete when merging is not completed completely)
Git branch-D Dev

 


Multi-person collaboration
(View remote database information)
Git remote
(View more details about the remote database)
Git remote-V

Push Dev Branch
Git push origin Dev

Capture Branch
(Clone)
Git clone [email protected]: taylorapril/test. Git
(For details, see git branch)
(Develop on the dev branch and create the dev branch of the remote origin to the local)
Git checkout-B Dev origin/dev
(Submit after modification)
Git commit-M "add"
Git push origin Dev
(When you push again after the submission)
(Specify the local Dev branch and remote origin branch link)
Git Branch
Git pull
Git commit-M "fixed"
Git push

 

 

Error

Error 1

$ Git push-u origin master
To [email protected]: taylorapril/test. Git
! [Rejected] Master-> master (fetch first)
Error: failed to push some refs to '[email protected]: taylorogl/test. Git'
Hint: updates were rejected because the remote contains work that you do
Hint: Not Have locally. This is usually caused by another repository pushing
Hint: to the same ref. You may be want to first integrate the remote changes
Hint: (e.g., 'git pull... ') before pushing again.
Hint: see the 'note about fast-forwards 'in 'git push -- help' for details.


Solution:
Git pull -- rebase origin master
Git push-u origin master

 

Error 2

$ Git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(Use "Git push" to publish your local commits)

Solution:
Git push

GitHub Common commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.