Common git commands

Source: Internet
Author: User

first, the initialization of
1. Configure User name
git config--global user.name "Hawk"
2. Configure Mail
git config--global user.email "[email protected]"
3. List all Configurations
git config-l
4. Abbreviation:
git config--global alias.co checkout
git config--global alias.ci commit
git config--global alias.br branch
git config--global alias.st status
git config--global alias.lg log--stat
second, the basic Operation
1. Help command
git help Command
2. Pull Code
git Pull # Get the latest code and merge automatically
git fetch # Gets the latest code, but does not merge
3. Add to Buffer
git Add File
git add *
git add-u # automatically tracks files, including files you delete automatically
4, modify the staging area
git rm File # Deletes the file and removes it from the cache
git rm file-cached # is only removed from the cache and does not delete files
5. Submit
git Commit-am "Comment" # Commit all Actions
git commit--amend # to modify the last commit annotation
6. View
1. View Submission History
git log--stat # show Details
git log file # Displays a log of a file
git log-p file # view diff for each modification
2. View the differences between files
git diff file # compare current and staging area file differences
git diff id1 Id2 # Compare differences between two commits
git diff--stat # show details
git diff--cached # shows all the current launches
3. See who changed each line of a file
git blame file # View files changed by person
7. Recovery
1. Git checkout file # Discard workspace modification
2, git reset--hard file # recover from staging area to working file, move head pointer
3, git revert HEAD # revert to the state of the last commit
8. Push
git push Origin master # pushes the local master branch to the Origin branch
Third, Branch
1. View
git branch-r # Viewing a remote branch
git branch-a # view all branches
git Branch # view current Branch
git Branch--merged # View branches that have been merged into the current branch
git Branch--no-merged # View branches that have not been merged into the current branch
2. Switch Branches
git checkout branchname # switch to a branch
3. Create a branch
git checkout-b branchname # Create a new branch and switch to the past
git checkout branchname
4. Delete Branch
git branch-d branchname
5. Merging branches
git merge Otherbranch # merges the current branch with the Otherbranch
git rebase # Update the newest branch
Four, version library
1. Initialize
1. Git init # Initializes a repository
2. Git clone address # clone remote code
3. Git remote add orgin address # Add the Repository Origin
Five, advanced features
1. Temporary Storage Management
git stash # cache Current Changes
git stash List # shows all caches of buffers
git stash Apply # application top-level cache
git stash Drop # Delete top-level cache
git stash Pop # apply top-level cache and delete
2. Tag
1. View
git tag # shows all the tags
git show TagName # Displays the information for a specific tag
2. Marking the label
git tag tagName # hit Tag
git tag-a tagname-m "Comment" # tag and add a note
3. Push
git push Origin tagName # pushes tags to remote
4. Delete tags
git tag-d tagName # remove tag locally
git push origin:refs/tags/tagname # delete tag in remote repository

Common git 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.