前言
最近把git仓库从github切换到gitee。然而在本地更换repo的时候遇到一些问题,各种谷歌也没解决掉,具体表现如下:
更换到gitee后执行git pull 仍然使用的是旧repo (github)的问题。因此整理一下git重命名repo的操作
解决方法传送门
重命名remote
git remote rename {old\_name} {new\_name}
添加新remote
git remote add {name} {git-repo}
在两个仓库都有内容的情况下更换 origin
git remote rename origin github
git remote add origin {new_repo}
git remote -v
rename出现的pull的仍然是旧repo的问题
简短版
$ git pull origin
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "github"]
url = git@old.git
fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
remote = github
merge = refs/heads/master
[remote "origin"]
url = git@new.git
fetch = +refs/heads/*:refs/remotes/origin/*
$ git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.
$ git pull -v
From new
= [up to date] master -> origin/master
= [up to date] release -> origin/release
Already up to date.
整个历程
$ git remote -v
$ git remote show origin
* remote origin
Fetch URL: git@new.git
Push URL: git@new.git
HEAD branch: master
Remote branches:
master new (next fetch will store in remotes/origin)
release new (next fetch will store in remotes/origin)
Local ref configured for 'git push':
master pushes to master (up to date)
$ git fetch origin
From new
* [new branch] master -> origin/master
* [new branch] release -> origin/release
$ git remote show origin
* remote origin
Fetch URL: git@new.git
Push URL: git@new.git
HEAD branch: master
Remote branches:
master tracked
release tracked
Local ref configured for 'git push':
master pushes to master (up to date)
$ git pull -v
Enter passphrase for key '/home/simon/.ssh/id_rsa':
From old
= [up to date] master -> github/master
= [up to date] release -> github/release
Already up to date.
$ git push origin master -v
Pushing to git@new.git
To new
= [up to date] master -> master
updating local tracking ref 'refs/remotes/origin/master'
Everything up-to-date
$ git pull origin
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "github"]
url = old
fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
remote = github
merge = refs/heads/master
[remote "origin"]
url = new
fetch = +refs/heads/*:refs/remotes/origin/*
$ git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.
$ git branch master -u origin/master
|