起因
因為作業的文件夾是從助教的remote repository上clone下來的這裡先稱那個git系統為系統A,所以原來.git的信息都是關於系統A的。但是我想把我的repository push到自己的remote 的系統B上。弄了很久,remote重置了,username和useremail也改了,但是還是push不了。
於是想到了以下這個比較極端的辦法。
- 刪除git配置
- git初始化
- git上傳三步曲
刪除git系統A配置
如果本地的working directory是在git系統A(比如github)master-M底下的分支,
一個比較極端的方法,就是刪除 .git文件夾,命令如下:
$rm -rf .git
git系統B初始化
因為 .git文件夾里有git的所有配置,如index等。再初始化git
$git init
這時需要看一下git的配置信息
$git config --list
檢查裡面的user.name 和user.email的信息是否和系統B的信息時候一致,如果不一致,則要用git config的命令去設置user.name和user.email(詳細命令可另外查找)。
設置完後再新增remote,命令如下
$git remote add origin https://username@git-system/username/repository_name.git
git系統B上傳三步曲
新增完remote後,再執行git三步曲
$git add .
$git commit -m "message"
$git push -u origin master
(如果git系統B的remote repository原來有檔案,就要merge),命令如下
$git pull origin your_branch
1~3點參考:
1. http://stackoverflow.com/questions/17291995/push-existing-project-into-github
2. https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3. https://gist.github.com/zenideas/3810627
我知道這個方法可能很極端,如果有人有更好的方法歡迎賜教!