Git basic commands--remote

Source: Internet
Author: User
Tags using git

git clone:

# Clone to < local directory name >< repository URL > < local directory name ># When cloning a repository, the remote host used is automatically named as Origin by Git. If you want to use a different hostname, you need to use the git clone command ---o jQuery https://github.com/jquery/jquery.git$ git Remotejquery

git clone will only clone the Master branch, if you want to clone all branches, Git clone after git fetch, or other commands

Git Remote:

  git remote add <shortname> <url>Add a new remote Git repository,<shortname> also known as "hostname"

$ git remoteorigin$ git remote add pb https://github.com/paulboone/ticgit$ git Remote-voriginhttps://github.com/schacon /ticgit (FETCH) originhttps://github.com/schacon/ticgit (push) pbhttps://github.com/paulboone/ticgit (FETCH) Pbhttps ://github.com/paulboone/ticgit (push)

You can now use strings in the command line pb instead of the entire URL. For example, if you want to pull the information that Paul has in the repository but you don't have, you can run git fetch pb :

$ git fetch pbremote:counting objects:43, done.remote:Compressing objects:100% (36/36), Done.remote:Total (Delta 1 0), reused (Delta 5) Unpacking objects:100% (43/43), done. From Https://github.com/paulboone/ticgit * [New branch]      master,     pb/master * [New branch]      ticgit     - > Pb/ticgit

Now Paul's master branch can be accessed locally pb/master -you can merge it into one of your own branches, or you can check out a local branch that points to that point if you want to see it.

The GIT Remote show command plus the host name allows you to view the details of the host.

$ git Remote show Origin*Remote Origin Fetch URL:SSH://example.com/path/toPush URL:SSH://example.com/path/toHEAD branch:master Remote branch:master tracked Local branch configured for 'git Pull': Master merges with remote Master Local ref configured for 'git push': Master pushes to master (fast-forwardable)

The GIT remote RM command is used to remove a remote host.

The GIT remote rename command is used to change the host's name.

RM < hostname >< original hostname > < new host name >

git fetch:

The git fetch command is used when the remote host's repository is updated (git terminology is called commit) and needs to be retrieved locally.

By default, git fetch retrieves updates for all branches (branch). If you want to retrieve only updates for a particular branch, you can specify a branch name.

$ git fetch < remote host name >< remote host name > < branch name > for example$ git fetch Origin Master 

The retrieved updates are read in the form of a "remote hostname/branch name" on the local host. For example, the Master of Origin host, must read with Origin/master.

Git branch:

The-r option of the git Branch command can be used to view the remote branch, the-a option to view all branches.

$ git branch-rorigin/-a* master  remotes/origin/master

The above command indicates that the current branch of the local host is master and the remote branch is origin/master.

Git Pull:

The purpose of the git pull command is to retrieve updates from a branch of a remote host and merge with the local designated branch.

$ git Pull < remote host name > < remote branch name >:< local branch name >

For example, retrieving the next branch of the Origin host, merging with the local master branch, needs to be written as follows.

$ GIT pull Origin next:master

If the remote branch is merged with the current branch, the part following the colon can be omitted.

$ GIT pull Origin Next

The above command indicates that the Origin/next branch is retrieved and then merged with the current branch. Essentially, this is equivalent to doing git fetch first and then git merge.

$ git fetch origin$ Git merge Origin/next

In some cases, Git automatically creates a tracking relationship (tracking) between the local branch and the remote branch. For example, in Git clone, all local branches default to the remote host with the same name branch, establish a tracking relationship, that is, the local master branch automatically "track" Origin/master branch.

Git also allows you to manually establish tracking relationships.

$ git Branch--set-upstream Master origin/next

The above command specifies that the master branch tracks the Origin/next branch.

If the current branch has a tracing relationship with the remote branch, git pull can omit the remote branch name.

$ GIT pull origin

The above command indicates that the local current branch is automatically merged with the corresponding Origin host "Trace branch" (Remote-tracking Branch).

If the current branch has only one trace branch, even the remote host name can be omitted.

$ git pull

The above command indicates that the current branch is automatically merged with the only one tracking branch.

If the merge requires Rebase mode, you can use the--rebase option.

$ git pull--rebase < remote host name > < remote branch name >:< local branch name >

If a remote host deletes a branch, by default, git pull does not delete the corresponding local branch while pulling the remote branch. This is to prevent git pull from inadvertently deleting the local branch because someone else is operating the remote host.

However, you can change this behavior, plus the parameter-p will delete the remote deleted branch locally.

$ git pull----P

git push:

The git push command is used to push updates to the local branch to the remote host.

$ git push < remote host name > < local branch name >:< Remote Branch name >

If you omit the remote branch name, it means that the local branch is pushed to the remote branch with which the trace relationship exists (usually the same name), and if the remote branch does not exist, it is created. Simple , matching, need to verify. For creating a new remote branch?

$ GIT push origin master

The above command indicates that the local master branch is pushed to the master branch of the Origin host. If the latter does not exist, it will be created. Simple , matching, need to verify.

If you omit the local branch name, it means that the specified remote branch is deleted because it is equivalent to pushing an empty local branch to the remote branch.

--delete Master

If there is a tracing relationship between the current branch and the remote branch, both the local branch and the remote branch can be omitted.

$ Git push origin indicates that the current branch is pushed to the corresponding branch of the Origin host

If the current branch has only one trace branch (meaning remote host name?) ), then the hostname can be omitted.

$ git push

If the current branch has a tracking relationship with multiple hosts, you can use the-u option to specify a default host so that you can use Git push without any parameters later.

The git push-u Origin master command pushes the local master branch to the origin host, specifying origin as the default host, and then using git push without any parameters. 

git push without any parameters pushes only the current branch by default, which is called simple mode. In addition, there is a matching method that pushes all local branches that have corresponding remote branches. Prior to Git version 2.0, the default is to use the matching method, which now defaults to Simple mode. If you want to modify this setting, you can use the git config command. (Does git push differentiate between simple and matching only without parameters?) )

$ git config----global Push.default Simple

In another case, the--all option is required to push all local branches to the remote host, regardless of whether there is a corresponding remote branch.

The $ git push-All Origin command indicates that all local branches are pushed to the Origin host. 

If the version of the remote host is newer than the local version, Git will give an error when pushing, requiring that the git pull merge differences be made locally before being pushed to the remote host. At this point, if you must push, you can use the--force option.

The $ git push-ForceOrigin command uses the--force option, resulting in an overwritten version of the update on the remote host. Unless you are sure you want to do this, you should avoid using the--force option as much as possible.

Finally, git push does not push tags (tag) unless you use the--TAGS option.

$ GIT push origin--tags

Reference:

  Http://www.ruanyifeng.com/blog/2014/06/git_remote.html

Git basic commands--remote

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.