1、查看遠(yuǎn)程分支
git branch -r
2、查看本地分支
git branch
二、創(chuàng)建和切換分支
1、創(chuàng)建新分支
git branch 新分支名稱(chēng)
2、切換分支
git checkout 分支名稱(chēng)
3、創(chuàng)建分支的同時(shí),切換到該分支上
git checkout -b 新分支名稱(chēng)
三、從遠(yuǎn)程倉(cāng)庫(kù)pull(拉取)代碼到本地分支
1、指定遠(yuǎn)程分支,和本地分支
git pull origin 遠(yuǎn)程分支名稱(chēng):本地分支名稱(chēng)
2、如果不寫(xiě)本地分支名稱(chēng),則默認(rèn)和遠(yuǎn)程分支同名 ,命令如下:
git pull origin 遠(yuǎn)程分支名稱(chēng)
四、將新分支推送到遠(yuǎn)程倉(cāng)庫(kù)
方法1:使用git命令
git push origin 分支名稱(chēng)
假設(shè)我本地創(chuàng)建了一個(gè)名為dev的分支,遠(yuǎn)程倉(cāng)庫(kù)還沒(méi)有這個(gè)分支,推送的命令是:
git push --set-upstream origin dev
五、刪除分支
1、刪除本地分支(不能刪除當(dāng)前所在的分支,如果要?jiǎng)h除,必須先切換到其他分支上)
git branch -d 分支名稱(chēng)
如果刪除時(shí)報(bào)錯(cuò):error: The branch ‘分支名稱(chēng)’ is not fully merged. (意思是:分支未完全合并)。解決方法是使用 -D 強(qiáng)制刪除,代碼如下:
git branch -D 分支名稱(chēng)
2、刪除遠(yuǎn)程分支
git push origin :分支名稱(chēng)
注意:分支名稱(chēng)前有個(gè)冒號(hào),分支名前的冒號(hào)代表刪除
六、合并分支
1、假如我們現(xiàn)在位于分支dev上,剛開(kāi)發(fā)完自己負(fù)責(zé)的功能,執(zhí)行了下列命令:
git add .
git commit -m '某某功能已完成,提交到[分支名稱(chēng)]分支'
git push -u origin 分支名稱(chēng)
2、首先切換到master分支上
git checkout master
3、如果是多人開(kāi)發(fā)的話(huà),需要把遠(yuǎn)程master分支上的代碼pull下來(lái)
git pull origin master
4、然后把dev分支的代碼合并到master上
git merge 分支名稱(chēng)
如果git merge的時(shí)候出現(xiàn)沖突,可以執(zhí)行下面的命令取消merge:
git merge --abort:
5、然后查看狀態(tài)
git status
6、最后一步,Push推送到遠(yuǎn)程倉(cāng)庫(kù)
git push origin master
-------------------------------------------------------------------我是分割線(xiàn)------------------------------------------------------
一.本地項(xiàng)目上傳公司GitLab步驟(教程如下鏈接!!!)
添加鏈接描述
二.本地項(xiàng)目更新了代碼,怎么提交新修改部分的
git status /查看當(dāng)前有哪些文件更新了 會(huì)紅色展示
這個(gè)時(shí)候?qū)⒛阈薷牡奈募峤坏綍捍鎱^(qū)
git add APP-META
這個(gè)時(shí)候你再去執(zhí)行 git status 會(huì)發(fā)現(xiàn)文件目錄下的文件名變成綠色了,這個(gè)時(shí)候就說(shuō)明提交到暫存區(qū)了
這個(gè)時(shí)候繼續(xù)執(zhí)行以下命令 就會(huì)更新到遠(yuǎn)程倉(cāng)庫(kù)了
git commit -m "自定義備注名稱(chēng)"
git pull origin 分支名稱(chēng)
git push origin 分支名稱(chēng)
三.日常提交代碼報(bào)錯(cuò)解決辦法:
git push -u origin master 報(bào)錯(cuò) 處理辦法
git remote -v
如果沒(méi)有反應(yīng),輸出以下命令
git remote add origin 倉(cāng)庫(kù)地址
成功后再輸出
git remote -v
就會(huì)顯示當(dāng)前遠(yuǎn)程的origin
繼續(xù)
git pull origin 分支名稱(chēng)
就成功了,拉到對(duì)應(yīng)的分支了
然后繼續(xù)
git push origin 分支名稱(chēng)
如有以下報(bào)錯(cuò) (紅字報(bào)錯(cuò))
不要慌 使用
git status
查看是不是最新的(正常情況下都是新的)
繼續(xù)操作
git pull --rebase origin 分支名稱(chēng)
返回正常
繼續(xù)
git push origin 分支名稱(chēng)
提交代碼成功!!!
這個(gè)時(shí)候去倉(cāng)庫(kù)檢查 就有了對(duì)應(yīng)的文件,看完請(qǐng)關(guān)注收藏,謝謝!
git -如何擺脫You are currently editing a commit while rebasing branch 或者分支名字后面出現(xiàn) REBASE 1/1
一個(gè)命令解決
git rebase --abort
終止變基操作并返回到先前的狀態(tài)
報(bào)錯(cuò)提示:
fatal: ‘origin’ does not appear to be a git repository
fatal: Could not read from remote repository.
! [rejected] PRE -> PRE (non-fast-forward)
error: failed to push some refs to ‘https://gitlab.com/.git’
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
On branch PRE
nothing to commit, working tree clean文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-643747.html
fatal: Not a valid object name: ‘master’.文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-643747.html
到了這里,關(guān)于本地項(xiàng)目提交代碼到git倉(cāng)庫(kù)詳細(xì)教程包含錯(cuò)誤解決辦法!!!的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!