git push 報錯! [remote rejected] ceshi -> ceshi (pre-receive hook declined)
上傳到gitlab倉庫報錯
! [remote rejected] ceshi -> ceshi (pre-receive hook declined)
error: failed to push some refs to 'http://47.95.225.115/android/android.git'
具體報錯資訊如下:
剛開始以為是使用者密碼錯誤,試了好多次,最後網上找到了報錯解決方法
git push不上去的原因在於所push的分支許可權為protected,只有專案的管理員或者專案的管理員指派的具有相應許可權的人才能進行push,要進行專案的push,有如下兩種方法:
1.新建其它分支,將專案push到新建的分支上,後期再進行merge
1.新建分支
git branch 分支名
2.切換分支
git checkout 分支名
3.上傳專案
git add .
git commit -m "提交資訊"
git remote add origin 遠端分支地址
git push -u origin 分支名
#報錯
如果輸入$ git remote add origin [email protected]:djqiang(github帳號名)/gitdemo(專案名).git
提示出錯資訊:fatal: remote origin already exists.
解決辦法如下:
1、先輸入$ git remote rm origin
2、再輸入$ git remote add origin [email protected]:djqiang/gitdemo.git 就不會報錯了!
3、如果輸入$ git remote rm origin 還是報錯的話,error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig檔案的內容
4、找到你的github的安裝路徑,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一個名為gitconfig的檔案,開啟它把裡面的[remote "origin"]那一行刪掉就好了!
如果輸入$ git push origin master
提示出錯資訊:error:failed to push som refs to .......
解決辦法如下:
1、先輸入$ git pull origin master //先把遠端伺服器github上面的檔案拉下來
2、再輸入$ git push origin master
3、如果出現報錯 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.
4、則需要重新輸入$ git remote add origin [email protected]:djqiang/gitdemo.git
使用git在本地建立一個專案的過程
$ makdir ~/hello-world //建立一個專案hello-world
$ cd ~/hello-world //開啟這個專案
$ git init //初始化
$ touch README
$ git add README //更新README檔案
$ git commit -m 'first commit' //提交更新,並註釋資訊“first commit”
$ git remote add origin [email protected]:defnngj/hello-world.git //連線遠端github專案
$ git push -u origin master //將本地專案更新到github專案上去
gitconfig配置檔案
Git有一個工具被稱為git config,它允許你獲得和設定配置變數;這些變數可以控制Git的外觀和操作的各個方面。這些變數可以被儲存在三個不同的位置:
1./etc/gitconfig 檔案:包含了適用於系統所有使用者和所有庫的值。如果你傳遞引數選項’--system’ 給 git config,它將明確的讀和寫這個檔案。
2.~/.gitconfig 檔案 :具體到你的使用者。你可以通過傳遞--global 選項使Git 讀或寫這個特定的檔案。
3.位於git目錄的config檔案 (也就是 .git/config) :無論你當前在用的庫是什麼,特定指向該單一的庫。每個級別重寫前一個級別的值。因此,在.git/config中的值覆蓋了在/etc/gitconfig中的同一個值。
在Windows系統中,Git在$HOME目錄中查詢.gitconfig檔案(對大多數人來說,位於C:\Documents and Settings\$USER下)。它也會查詢/etc/gitconfig,儘管它是相對於Msys 根目錄的。這可能是你在Windows中執行安裝程式時決定安裝Git的任何地方。
配置相關資訊:
2.1 當你安裝Git後首先要做的事情是設定你的使用者名稱稱和e-mail地址。這是非常重要的,因為每次Git提交都會使用該資訊。它被永遠的嵌入到了你的提交中:
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
2.2 你的編輯器(Your Editor)
現在,你的標識已經設定,你可以配置你的預設文字編輯器,Git在需要你輸入一些訊息時會使用該文字編輯器。預設情況下,Git使用你的系統的預設編輯器,這通常可能是vi 或者 vim。如果你想使用一個不同的文字編輯器,例如Emacs,你可以做如下操作:
$ git config --global core.editor emacs
2.3 檢查你的設定(Checking Your Settings)
如果你想檢查你的設定,你可以使用 git config --list 命令來列出Git可以在該處找到的所有的設定:
$ git config --list
你也可以檢視Git認為的一個特定的關鍵字目前的值,使用如下命令 git config {key}:
$ git config user.name
2.4 獲取幫助(Getting help)
如果當你在使用Git時需要幫助,有三種方法可以獲得任何git命令的手冊頁(manpage)幫助資訊:
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
例如,你可以執行如下命令獲取對config命令的手冊頁幫助:
$ git help config