切换git存储库之间的跟踪

时间:2017-07-13 09:29:46

标签: git

我刚刚创建了一个新的远程存储库,然后添加,提交并将所有本地存储库文件推送到这个新的远程存储库。

git add -A
git commit -m "all files added"
git push newRepo master

在我这样做之前,我正在推送到另一个存储库,同时保留大多数文件未跟踪以及不对大多数文件进行更改。

> git status

On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

现在我的本地存储库位于oldRepo 2提交之前,并且似乎在newRepo和本地存储库之间跟踪了更改。如何恢复oldRepo和我的本地仓库之间的跟踪?

所以有2个远程存储库:newRepo和oldRepo +我的本地存储库 我需要在本地和oldRepo之间进行跟踪。

3 个答案:

答案 0 :(得分:1)

要制作本地分支跟踪remote/branch,只需执行

即可
git branch -u remote/branch branch

branch默认签出分支。

--set-upstream-to

答案 1 :(得分:0)

如果要删除旧存储库,则可以运行git remote remove origin如果origin是旧存储库的名称。如果您希望将旧存储库保留为新存储库的镜像,则可以在原点上推送提交:git push origin master

希望这会有所帮助。

答案 2 :(得分:0)

非常简单的步骤: -

打开命令提示符或终端并键入

git config -e

你会看到这种内容

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = <new_repo>
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        email = <local_user>
        name = Atul Agrawal

~                                                                                                                     
~                          

将原始网址更改为旧网址并保存此文件。您将配置旧存储库。

相关问题