Git Learning (3) --- remote Repository

Source: Internet
Author: User
1. Purpose This article describes how to operate the GIT remote database, including adding and deleting remote databases, viewing remote databases, obtaining and pushing operations, and creating and deleting remote branches.
All operations involved in this article are performed in the Ubuntu 14.04 environment, and the GIT version is 1.9.1.


2. add and delete remote libraries. Use the GIT remote add remote-name URL Command to add a remote library named remote-name. The address is URL; use the GIT remote remove remote-name command to delete the remote database named remote-name. Use the GIT remote rename oldname newname command to rename the remote database name from oldname to newname.
For example, use the GIT init command to initialize the local repository, and then use git remote add origin https://github.com/luomoweilan/blog.gitcommand to add a remote repository named origin to use the GIT remote rename origin blog command to rename the remote repository name; finally, use the GIT remote remove blog command to delete the remote library blog.



3. view the remote database. Run the GIT remote-V command to view the list of remote databases that have been added. Run the GIT remote show remote-name command to view the details of the remote database named remote-name.
The information includes the URL address for obtaining and pushing the remote database, the branch where the head is located, and the branch list owned by the remote database.
If an untracked branch exists in the local repository, you can use the GIT branch-B local-branch remote-branch command to create a new local-branch in the local repository.
If an outdated branch exists in the local repository, you can use the GIT remote prune branch-name command to clear the outdated branch in the local repository.



4. Get the remote library content. Use the GIT fetch remote-name command to get the content from the remote Library to the local repository, but it is not integrated into the local branch, use the GIT merge remote-name/branch-name command to merge the branch content of the remote database into the local branch.
Note: The git pull remote-name branch-name command is equivalent to a collection of git fetch and git merge commands.
For example, use the GIT fetch origin command to obtain the content of the remote database origin to the local repository, and then use the GIT merge origin/Master command to merge the remote database master branch into the local master branch.



5. Push content to the remote database. Use the GIT push remote-branch-name command to push the content of the local branch-name branch to the branch-name branch of the remote database.

6. When the GIT remote show remote-name command is used to create and delete remote database branches to view remote database information, it is found that there are remote database branches not tracked by the local database, you can use the GIT branch-B local-branch remote-branch command to create a local-branch in the local database, and the content is consistent with that in the remote-branch.
Run the GIT remote-Name: branch-name command to delete the branch-name branch of the remote database.



VII. Summary This article describes how to operate the GIT remote database. You must be familiar with the commands related to git remote.
Note the following two points:
1. It is not recommended to use the GIT pull command. You should first use the git fetch Command to synchronize the content of the remote database to the local database, and then use git merge to merge the content into the branch of the local repository, which is safer.
2. The command to delete a remote database branch is GIT push origin: branch-name, which is not easy to remember.


Copyright statement: original works. For non-commercial reproduction, please indicate the source. For commercial reproduction and publishing, please contact the author.

Git Learning (3) --- remote Repository

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.