基本操作
1、首先需要在gitlab上新建一個空項目
2、編輯項目名稱
3、在本地電腦上新建一個空的文件夾(或者是一個固定統(tǒng)一的文件夾),方便后續(xù)找到,這里會將gitlab的項目拉到這個文件內(nèi),點(diǎn)擊進(jìn)入這個文件夾,右鍵選擇git bash here。
4、輸入 git clone 地址
,此地址可以在1、2步中建好的gitlab項目上拷貝。
5、此時看本地電腦會出現(xiàn)在gitlab上新建的項目。
6、將要上傳的所有代碼和文件復(fù)制到該目錄下 。
注意,此處所在的分支是main,想要將代碼上傳到別的分支上,需要先在gitlab新建分支master, 然后輸入代碼: git checkout master
7、依次輸入代碼
git init
git add ./
git commit -m '注釋'
git push (輸完之后,會彈出框,輸入郵箱和密碼)
8、刷新gitlab頁面,切換到剛才代碼上傳的分支下,上傳成功。
問題
1、初始化git項目時,報錯Reinitialized existing Git repository in…
原因:該路徑中已經(jīng)存在.git文件了。
解決方法:在當(dāng)前文件下的控制臺中輸入 ls-a 查看,有.git 的話,使用 rm -rf .git
刪除之后重新初始化就可以。
2、push時報錯No configured push destination。
$ git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using
git remote add <name> <url>
and then push using the remote name
git push <name>
原因:沒有配置要推送的倉庫
解決方法:文章來源:http://www.zghlxwxcb.cn/news/detail-483930.html
git remote add origin 'https://git.....'
git push -u origin 分支名
3、git push失敗,提示! [rejected] master -> master (fetch first)error: failed to push some refs to ‘https://git…’
原因:gitlab中的README.md文件不在本地代碼目錄中
解決方法:執(zhí)行git pull --rebase origin master
命令將README.md拉到本地,然后執(zhí)行git push -u origin master
就可以成功了文章來源地址http://www.zghlxwxcb.cn/news/detail-483930.html
到了這里,關(guān)于gitlab上傳新項目全過程+常見問題解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!