GIT manual book scrap

这篇博客详细介绍了如何使用Git进行远程协作,包括查看远程仓库、添加远程仓库、拉取和推送数据。此外,还讲解了Git的分支管理,如创建、合并和解决冲突。还涉及到了Git的远程分支、跟踪分支以及rebasing操作。同时,文章讨论了Git在服务器上的部署,包括Git服务器协议、设置bare仓库和GitLab的使用。
摘要由CSDN通过智能技术生成

2.Git Basics

2.5.GitBasics - Working with Remotes

To be able to collaborate on any Git project, you need to know how to manage your remote repositories. Remote repositories are versions of your project that are hosted on the internet or network somewhere. You can have several of them, each of which generally is either read-only or read/write for you. Collaborating with others involves managing these remote repositories and pushing and pulling data to and from them when you need to share work. Managing remote repositories includes knowing how to add remote repositories, remove remotes that are no longer valid, manage various remote branches and define them as being tracked or not, and more. In this section, we’ll cover some of these remote-management skills.

note:

Note Remote repositories can be on your local machine.
It is entirely possible that you can be working with a “remote” repository that is, in fact, on the same host you are. The word “remote” does not necessarily imply that the repo is somewhere else on the network or Internet, only that it is elsewhere. Working with such a remote repo would still involve all the standard pushing, pulling and fetching operations as with any other remote.

Showing your remotes

To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you’ve specified. If you’ve cloned your repository, you should at least see origin — that is the default name Git gives to the server (you cloned from:

$ git clone https://...
...
$ cd ticgit
$ git remote
origin

You can also specify -v, which shows you the URLs that Git has stored for the shortname to be used when reading and writing to that remote:

$ git remote -v
origin	https://github.com/schacon/ticgit (fetch)
origin	https://github.com/schacon/ticgit (push)

If you have more than one remote, the command lists them all.

Notice that these remotes use a variety of protocols; we’ll cover more about this in Getting Git on a Server.

Adding Remote Repositories

We’ve mentioned and given some demonstrations of how the git clone command implicitly adds the origin remote for you.

how to add a new remote?

run git remote add <shortname> <url>

$ git remote add pd https://github.com/paulboone/ticgit

Fetching and Pulling from Your Remotes

$ git fetch <remote>

This command pulls down all the data from that remote project that you don’t have yet. After you do this, you should have references to all the branches from that remote, which you can merge in or inspect at any time.

It’s important to note that the git fetch command only downloads the data to your local repository — it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.

If your current branch is set up to track a remote branch (see the next section and Git Branching), you can use the git pull command to automatically fetch and then merge that remote branch into your cur branch. and by default, the git clone command automatically sets up your local master branch to track the remote master branch (or whatever the default branch is called)

you can run this to push any commits you’ve done to the server:

$ git push origin master


This command works only if …and if nobody has pushed in the meantime. If you and someone else clone at the same time and they push upstream and then you push upstream, your push will rightly be rejected. You’ll have to fetch their work first and incorporate it into yours.

[ incorporate ]: to include sth so that it forms a part of sth. 吸收 absorb, integrated, contain, involve. -corporate,全体的 公司的



Inspecting a Remote

see more information about a remote

$ git remote show origin
* remote origin
  Fetch URL: https://github.com/schacon/ticgit
  Push  URL: https://github.com/schacon/ticgit
  HEAD branch: master
  Remote branches:
    master                               tracked
    dev-branch                           tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

master merges with remote master

For example, it tells you that if you’re on the master branch and you run git pull, it will automatically merge the remote’s master branch into the local one after it has been fetched.

It also tells you which remote branches on the server you don’t have.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值