Git Common Command Daquan

Source: Internet
Author: User
Tags commit diff version control system git clone
Git is a very powerful distributed version control system. It is not only suitable for managing the source code of large open source software, but also has many advantages in managing private documents and source code.

Git Common Operations Command: 1). Basic Configuration
Configure User: $git config--global user.name "username" configuration message: $git config--global user.email "xxx@xx.com" configuration color: $git config-- Global Color.ui "Always"

Configuration aliases: $git config--global alias.st status

View users: $git config--list

Initialize the local repository: $git Init


2). Remote Warehouse related commands

View remote repositories: $ git remote-v

Displays the resources in origin of the remote library: $git Remote show Origin

Add remote repository: $ git remote add [name] [url]

Delete Remote repository: $ git remote RM [name]

Modify remote repository: $ git remote set-url--push [name] [Newurl]

Checkout warehouse: $ git clone [url]

Pull remote repository: $ git fetch [remotename] [Localbranchname]

Push remote repository: $ git push [remotename] [Localbranchname]

* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

$git Push Origin Test:master//submit local Test branch as remote Master Branch

$git Push Origin test:test//submit local test branch as remote Test branch


3). Branch (branch) operation related commands local branch:

View local branch: $ git Branch

View all branches: $ git branch-a

Rename Branch: $git branch-m [Branchname] [newname]

Create local branch: $ git branch [branchname]----Note that the new branch will not automatically switch to the current branch after it is created

Switch branches: $ git checkout [branchname]

Create and switch A new branch: $ git checkout-b [branchname]

Delete Branch: $ git branch-d [branchname]-----d option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge.

If you want to forcibly delete a branch, you can use the-D option (you need to switch to another branch first)

Merge branch: git merge [branchname]----Merge a branch named [Branchname] with the current branch

* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

$git symbolic-ref HEAD Refs/heads/[name]

$rm. Git/index

$git CLEAN-FDX

Git push Origin Master:hb-dev associate a local library with a library on the server
Create a local branch and a remote link relationship: Git branch--set-upstream branch-name origin/branch-name


Remote Branch: Add "-r" to be similar to local operation

Create \ Push to remote branch: Git push origin [branchname]

View Remote branch: $ git branch-r

Switch to remote branch: $git checkout--track Origin/dev

Delete Remote branch: $git branch-rd [branchname] or git push origin:heads/[name] or GIT push origin: [Branchname]


4) version (tag) operation related commands

View version: $ git tag

Create version: $ git tag [name]

Create annotated tag:$ git tag-a [name]-M ' YourMessage '

Delete tag: $ git tag-d [name]


Merge the remote repository's tag to local: Git pull Origin--tags


View remote version: $ git tag-r

Push all non-push tags: $git push origin [Branchname]--tags, no parameters--tags can also be pushed (commit and tag), not measured

Delete Remote Tags: 1. Delete 2.$ git push origin:refs/tags/[name locally first]



5) Sub-module (submodule) Related Operations Command

Add sub-module: $ git submodule add [url] [path]

Example: $git submodule add Git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out

Update submodule: git submodule update----need to run every time you update or switch branches

To delete a submodule: (4 steps away OH)

1) $ git RM--cached [path]

2) Edit the ". Gitmodules" file to delete the relevant configuration node of the Submodule

3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule

4) Manually delete the remaining sub-modules directory


6) Ignore some files, folders do not submit

Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as

Target

Bin

*.db


7) file Add file to warehouse staging area: $git add [filename] Delete file:               &NBSP ;         $git rm [filename]  git rm-f a.a forcibly remove modified files (removed from staging area and workspaces)
git RM--cached a.a Remove Files (removed from staging area only)  

8) Local warehouse common operations workspace: strong> View working directory Status: $ git status
view updates that have not yet been staged: $git diff 

To view an update that has not yet been submitted: $git diff--cached or git diff--staged revert to staging area/Repository status: $git checkout--[filename1,filename2 ...] Back to the last git commit or git add Undo staging Area Modify: Git reset HEAD file
Index Area: add: Git add ...
Version Library: Commit All changes: $git commit-a commit all changes to the current repos
commit and see the difference: $git commit-v
Submit with Comment: $git commit-m "comment"
See already submitted: $git Ls-files View commit log: $git log

Get: $git fetch is equivalent to getting the latest version from remote to local, not automatically merge

Merge: $git merge Origin/dev merges branch Dev with the current branch

Disable Fast forward Merge: $git merge--no-ff-m "comment" Dev

Fetch: $git pull gets and merges the current branch

Stash : Staging: $git Stash "Store" the current work site (git stash push) to view the job site: $git stash List recovery does not delete: $git stash @{0} (.. Hashid..)

Recover and delete: $git stash pop


10) Advanced subject record each command: $git reflog

Git revert is to undo a certain action, the commit before this operation will be preserved


Fallback to previous version: $git reset--hard head^

Fallback to Top N version: $

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.