Common commands for Git code management

Source: Internet
Author: User
Tags using git

1) Remote Warehouse related commands


Checkout warehouse: $ git clone git://github.com/jquery/jquery.git
View remote repositories: $ git remote-v
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]
Pull remote repository: $ git fetch [remotename] [Localbranchname]
Push remote repository: $ git push [remotename] [Localbranchname]

2) Branch (branch) operation related commands


View local branch: $ git Branch
View Remote branch: $ git branch-r
Create local branch: $ git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created
Switch Branch: $ git checkout [name]
Create a new branch and switch immediately to the new branch: $ git checkout-b [name]
Delete Branch: $ git branch-d [name]-----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
Merge branch: git merge [name]----Merge the branch with the name [name] with the current branch
Create a remote branch (local branch push to remote): $ Git push origin [name]
Delete Remote branch: git push origin:heads/[name]
I created a issue5560 branch from the master branch and made some changes, using GIT push Origin master to commit, but the result was ' everything up-to-date ', and the problem was because git push Origin Master commits the master branch by default in the local branch without the track remote branch, because the master branch defaults to the Origin Master branch, where you use Git push Origin issue5560:master You can push the issue5560 to the remote Master branch.
You can do this 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.

$ GIT push origin test:master//submit local Test branch as Remote Master Branch//As if writing this sentence, remote GitHub will automatically create a test branch
$ GIT push origin test:test//submit local test branch as remote Test branch

What if you want to delete a remote branch? Similar to the above, if: The left branch is empty, then delete: The remote branch on the right.

$ git push origin:test//Just submit to remote test will be deleted, but local will also be saved, do not worry

3) version (tag) operation related commands


View version: $ git tag
Create version: $ git tag [name]
Delete version: $ git tag-d [name]
View remote version: $ git tag-r
Create a remote version (local version push to remote): $ Git push origin [name]
Delete Remote version: $ git push origin:refs/tags/[name]
Push all tag:git push Origin--tags

Tag Move out branch:
git checkout tagname
Git checkout-b new_branch_name

4) Git stash staging related commands

Git stash: Backs up the contents of the current workspace, reads the content from the most recent commit, and makes the workspace guarantee consistent with the last commit. At the same time, save the current workspace content to the git stack.
Git stash pop: reads the last saved content from the Git stack and restores the workspace. Because there may be multiple stash content, the pop reads the content from the most recent stash and recovers it by using a stack to manage it.
Git stash list: Displays all the backups in the GIT stack and can use this list to decide where to recover from.
Git stash clear: Empty the git stack. Using graphical tools such as GITG, you will find out which nodes of the original stash have disappeared.

5) Git rebase use

Current branch issue develop, pull the latest code from master
Git pull--rebase Origin master or git rebase develop
First, the code for the develop branch is checkout out as the working directory
The Master branch is then created from the develop branch with all the changed patches, sequentially. If there's no problem with the patching process, Rebase's done.
If there is a problem with patching, you will be prompted to handle the conflict. Well, you can run Git rebase–continue and continue until you finish.
If you don't want to, you still have two options, one is to abandon the rebase process (run Git rebase–abort), and the other is to replace the current branch (git rebase–skip) directly with the Test branch.

Common commands for Git code management

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.