分類
git 錯誤紀錄

[GitLab Issue] You are not allowed to push code to protected branches on this project

Scenario

Local 端在 master branch 上執行 git push origin master 後出現以下 Error

remote: GitLab: You are not allowed to push code to protected branches on this project.
To http://xxx.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘http://xxx.git’

Root Cause

關鍵字為
You are not allowed to push code to protected branches on this project

從 Google 得知為 GitLab 預設專案的 master branch 為 Protected,無法直接push commit 到 remote 的 master branch。

Solution

A. 透過GitLab的管理者權限將該專案的protected branch關閉。
GitLab->點擊該傳案->左方最下面的settings -> Repository ->點擊 Protected Branch的Expand -> 點擊 Unproject

B. 先git push 到其他branch上,再到GitLab將該branch merged到master(待測)

分類
git 錯誤紀錄

Git error: 解決在Gerrit網頁上submit patch set 出現衝突的情況

Cause:

在 Gerrit 等待 code review 通過期間,若有協同開發者先 merge commit ,且該 commit 和 自己的commit 發生衝突的情況

Solution:

1.
在發生conflict branch上 執行
git pull --rebase origin master
此指令說明如下
This command will fetch new commits from the remote and then rebase your local commits on top of them. It will temporarily set aside the changes you’ve made in your branch, apply all of the changes that have happend in master to your working branch, then merge (recommit) all of the changes you’ve made back into the branch. Doing this will help avoid future merge conflicts. Plus, it gives you an opportunity to test your changes against the latest code in master.
Once you are satisfied with your change set and you’ve rebased against master, you are ready to push your code to Gerrit for review.
簡單的說:把master上已合併的commit(但在目前branch不存在),接到目前的branch,再把
目前branchcommit接到最後面(最新)
當然在Gerrit 網頁上合併會發生衝突,所以執行這個指令之後在本地端也會發生衝突,
把執行後的提示紀錄下來如下
When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase –abort".
接下來的步驟為
2. 修改發生衝突的地方,使用vim修改
3. 把修改後的檔案全部 git add
4. git add 所有的檔案之後執行 git rebase –continue
5. 最後 git push origin HEAD:refs/for/master
6. 必須重新等待code review
分類
git 錯誤紀錄

Git error: Permission denied (publickey). fatal: The remote end hung up unexpectedly

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

 
Root Caused:
在本機端 git clone 專案時,使用指令時權限錯誤
Solution:
在輸入git clone 指令時切換到適合的權限,再輸入
或在放置專案的地方輸入 sshp-add

分類
git 錯誤紀錄

Git error: Permission denied (publickey) fatal: Could not read from remote repository

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

 
Root Caused:
通常是 SSH Key 沒有加入的問題
Solution:
1.重新產生 SSH Key
終端機輸入

ssh-keygen –t rsa –b 2048


2.顯示 SSH Key
終端機輸入

cat ~/.ssh/id_rsa.pub


3.貼到 Gerrit 中
Settings -> SSH Public Keys -> add key 
貼上第2步中所有的內容