之前在學校實驗室服務器上建了一個git遠程倉庫,存放我寫的express項目代碼。后來由於出去實習,就無法訪問那個遠程倉庫了,因為它在校園網內。
還好我的筆記本中有這個項目完整的本地倉庫,於是我就試着在阿里雲中新建一個倉庫,這樣就能把我的本地倉庫的代碼都上傳上去。
首先,我再home目錄創建了倉庫文件夾,然后在這個文件夾下創建一個子文件夾作為我express項目的倉庫目錄
mkdir /home/repository/meadowlark.git
在meadowlark.git目錄下,運行
git --bare init
簡單兩步,服務器端的任務就完成了。
然后,我再本地倉庫運行
git remote -v
可以看到之前設置的遠程倉庫地址
origin root@10.21.20.***:/home/nodejs/meadowlark.git (fetch)
origin root@10.21.20.***:/home/nodejs/meadowlark.git (push)
現在已經沒用了需要刪掉。
git remote rm origin
然后設置新的遠程倉庫地址
git remote add origin username@192.168.1.1:/home/repository/meadowlark.git
到這里基本已經結束了,我試着運行git push, bash提示我
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
按照提示輸入上面的命令之后,本地倉庫的代碼都已經上傳到遠程倉庫了。
以后使用
git push
也沒再出現問題。
朋友想拉取我的項目代碼,我讓他直接輸入
git clone root@192.168.1.1:/home/repository/meadowlark.git
就能把代碼拉取下來,這也說明我們的遠程倉庫是沒有問題的。