markdown 将远程源/主服务器合并到新的本地存储库中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 将远程源/主服务器合并到新的本地存储库中相关的知识,希望对你有一定的参考价值。

This little dance is needed to merge in the remote origin/master to a fresh local (one created *without* cloning the remote, such as by a tool like [pass](https://www.passwordstore.org/)). I don't know if there is a better way?

You need to do this when

 * you have another application which can use git for storing data, and you need to fill it with history from a common remote, but the application doesn't support `git clone`, only `git init` type operations
 * you have a local repository with local changes that you want to keep, but still merge in the origin (although you could go the other way, I think?)

Use commands like these to merge in a remote to your local master, as the new origin:

```
git remote add origin git@github.com:user/repo
git fetch origin
git checkout origin/master
git checkout -b temp
git checkout -B master temp
git branch -d temp
git branch --set-upstream-to=origin/master master
```

An explanation of what these commands do:

 * Add the remote, call it `origin`
 * fetch the data
 * switch to the `origin/master` branch just fetched
 * create a new branch `temp` from the current branch (`origin/master`) - merges all the data to `temp`
 * reset `master` from the `temp` branch - merges all the data to the local `master` branch
 * delete the `temp` branch
 * set *upstream* tracking for `master` as `origin/master`

以上是关于markdown 将远程源/主服务器合并到新的本地存储库中的主要内容,如果未能解决你的问题,请参考以下文章

如何将分支的内容复制到新的本地分支?

为什么我的远程主分支中的更改没有被拉到本地主分支中?

从克隆切换到新的fork保留更改

git提交时,新建分支,提交内容,再合并到主分支

git提交时,新建分支,提交内容,再合并到主分支

git 代码分支合并merge提交新修改远程以及本地分支