Git Common Commands Collection

Source: Internet
Author: User

remote Warehouse related commands
Clone a remote repository: Git clone git://github.com/jquery/jquery.git view remote repository: Git remote-v to add repository: Git remote adds [ Name] [url] Delete remote repository: Git remote RM [name] Modify the repository: Git remote set-url--push [remotename] [Newurl] Pull remote repository: git pulls [rem Otename] [remotebranchname]:[localbranchname] push remote repository: git push [remotename] [Localbranchname]:[remotebranchname] 
Branch Command (branch)
View local branch: Git Branch View remote branch: Git branch-r View all branches: Git branch-a Create a local branch: Git branch [name]//note The new branch will not automatically switch to the current branch after it is createdswitch branches: git checkout [Branchname] creates a new branch and immediately switches to a new branch: Git checkout-b [Name] Merge branch: git merge [Branchname]//merge branches with name [Branchname] into the current branchpush local branch to remote: git push [remotename] [Localbranchname]:[remotebranchname]//If the remote branch does not exist, the remote branch is created automaticallyDelete local branch: Git branch-d [Branchname]//The [-d] option removes only the branches that have 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] optionDelete Remote branch: v1 in git.After 7.0, you can use this syntax to delete a remote branch: git push--DeleteOrigin Branchname Otherwise, you can use this syntax to push an empty branch to a remote branch, which is actually equivalent to deleting a remote branch: Git push Origin: [Remotebranchname]

1. If there is a correspondence between the local branch and the remote branch, you can submit to the remote branch directly under the branch via git push.

2. View the correspondence between the remote Warehouse branch and the local Warehouse branch (Pull,push), such as the Origin warehouse:

Also shows the resources in the remote repository origin

git remote show origin

3. A local branch commits to a branch of the remote repository, taking the local test branch as an example, as follows:

git push [remotename] test:master  //  submit local Test branch as remote Master branch git push [remotename] test:test
   
    // 
     submit local test branch as remote Test branch
   

4. Submit the code to different branches of different warehouses: https://www.v2ex.com/t/95460

git remote add github [url]git remote add gitcafe [url]git push GitHub master:mastergit push Gitcafe Master:cafe- Pages
drawdown command (reset)

Revert to a previous version of a file that has been submitted to the repository or cache.

Drawdown command template: Git reset [--param] [Commit ID] drawdown to the specified version: git reset--Hard 9ca489438651f44cf65366e3bfab09527c8235ae "commit ID on log" drawdown to last 1 versions: git reset--hard head^drawdown to last 2 versions: git reset--hard head^^drawdown to last 10 versions: git reset--hard head~10drawdown to last 0 versions: git reset--Hard HEAD//the latest version of the local repositoryDrawdown to remote 0 versions: Git reset–-hard [remotename]/[branchname]//that is, the latest version of the remote Repository, such as: Git Reset–-hard origin/masterretracement parameter explanation:--mixed reset HEAD and index default options. Repository and buffers are rolled to the specified version, but the working directory is not affected--Soft reset only HEAD back to the repository, the buffer and working directory will not be changed--Hard reset HEAD, index and working tree all files are not preserved--Merge reset HEAD, index and working tree merge the specified version with the current staging area and workspace files--keep Reset HEAD but keep local changes
drawdown command (checkout)

Reverts to the unmodified state when the workspace file has been modified but not yet committed to the repository or cache.
(The Webstorm editor is called revert, where the revert can also be withdrawn files that have been submitted to the cache)

Undo one of the uncommitted changes: Git checkout dev/filename.js undo all uncommitted changes: git checkout.
 configuration Command (config)
--Global alias. [AliasName] [CommandName]     // For example, git config--global alias.st status, so that you can use Git status to view the status of a file and now git St.  Local Configuration path: [Current project]/.git/config Global configuration path: [user]/.gitconfig Configuration You can edit the. gitconfig file directly, more conveniently, as follows:    [ User]        = barrior        = [email protected]    [alias]        = status        = Checkout        = Branch        = Commit
Difference Comparison command (diff)

This should be viewed with a tool to be more intuitive.

--cached [File] or git diff--staged [file]    ///  If there is no file, the difference is listed for all files
Other Commands
View current status: Git status commits a file (workspace) to the cache: git add [path]     // [path] can be a file or a directory  -m ' message    '-am ' message '            //  [-a] stands for Add, note: This command commits all modified files but does not submit the newly created file  -p [file] push files to a temporary space: git stash push files from temporary space pops down: git stash pop
file Ignore (. gitignore)

The. Gitignore profile is used to configure files that do not need to be versioned, and you can use the shell command touch. Gitignore to create this file in Git Bash.

1. Configuration syntax:

    • Lines that begin with the pound sign "#" are treated as comments.
    • Start with a slash "/" to indicate the directory.
    • Use the asterisk "*" to pass multiple characters.
    • Use a question mark "?" to pass a single character.
    • The square brackets "[]" contain a list of matches for a single character.
    • The exclamation point "!" means that the file or directory that was excluded from the previous pattern is not ignored and cannot be re-included if the parent directory of the file is excluded.

2. Example:

Rule:test/* Description: Ignores all contents of the test directory, note that the rule is ignored either in the/test/directory under the root directory or in a subdirectory/child/test/directory:/test/* Description: Ignores all content rules for the/test/directory under the root directory:Test Description: Ignore test file and test directory rule:test/ Description: Only the test directory is ignored, test file rules are not ignored:test
     !test/ Description: Only the test file is ignored, the test directory rule is not ignored:/test Description: Only the test file and directory under the current directory is ignored, and the subdirectory's test is not in the Ignore rule:*.[ OA] Description: Ignores all file rules that end in. O or. A:**/node_modules/ Description: Ignores all folders named Node_modules, and writes directly Node_ Like modules/ .

3. Example:

Rules:     /*     !/test    /test/*    !/test/inner.js Description: Ignores all content, but does not ignore/test directories and/test/inner.js files under the root directory 
git terminal preferences
    1. In Git Bash command line terminal, right-click Options, there are many display settings, such as setting the default terminal size, transparency, font size, etc., can make the vision more comfortable.
    2. After the setup is complete, a. minttyrc file is generated under the [Users] folder, saved to the cloud, and later re-installed in the system or other computer, directly glued to the [user] folder can be used.

Reference:

Git Common Commands Encyclopedia: http://blog.csdn.net/dengsilinming/article/details/8000622

Git Website: https://git-scm.com/book/zh/v2

Http://www.cnblogs.com/haiq/archive/2012/12/26/2833746.html

http://blog.csdn.net/benkaoya/article/details/7932370

Other resources

Git Common Commands Collection

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.