github常見操作和常見錯誤!錯誤提示:fatal: remote origin already exists.

如果輸入$ git remote add origin git@github.com:djqiang(github帳號名)/gitdemo(項(xiàng)目名).git

提示出錯信息:fatal: remote origin already exists.

解決辦法如下:

1、先輸入$ git remote rm origin

2、再輸入$ git remote add origin [git@github.com:djqiang/gitdemo.git](mailto:git@github.com:djqiang/gitdemo.git) 就不會報錯了!

3、如果輸入$ git remote rm origin 還是報錯的話,
     error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig文件的內(nèi)容

 4、找到你的github的安裝路徑,我的是 
      C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

 5、找到一個名為gitconfig的文件,打開它把里面的[remote "origin"]那一行刪掉就好了!

如果輸入$ ssh -T git@github.com

出現(xiàn)錯誤提示:Permission denied (publickey).因?yàn)樾律傻膋ey不能加入ssh就會導(dǎo)致連接不上github。

解決辦法如下:

1、先輸入$ ssh-agent,再輸入$ ssh-add ~/.ssh/id_key,這樣就可以了。

2、如果還是不行的話,輸入ssh-add ~/.ssh/id_key 命令后出現(xiàn)報錯Could not open a connection to your authentication agent.解決方法是key用Git Gui的ssh工具生成,這樣生成的時候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行來做。

3、最好檢查一下在你復(fù)制id_rsa.pub文件的內(nèi)容時有沒有產(chǎn)生多余的空格或空行,有些編輯器會幫你添加這些的。

如果輸入$ git push origin master

提示出錯信息:error:failed to push som refs to .......

解決辦法如下:

1、先輸入$ git pull origin master //先把遠(yuǎn)程服務(wù)器github上面的文件拉下來

2、再輸入$ git push origin master

3、如果出現(xiàn)報錯 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 [git@github.com:djqiang/gitdemo.git](mailto:git@github.com:djqiang/gitdemo.git)

使用git在本地創(chuàng)建一個項(xiàng)目的過程

$ makdir ~/hello-world //創(chuàng)建一個項(xiàng)目hello-world

$ cd ~/hello-world //打開這個項(xiàng)目

$ git init //初始化

$ touch README

$ git add README //更新README文件

$ git commit -m 'first commit' //提交更新,并注釋信息“first commit”

git remote add origin [git@github.com:defnngj/hello-world.git](mailto:git@github.com:defnngj/hello-world.git) //連接遠(yuǎn)程github項(xiàng)目 git remote remove origin git@github.com:defnngj/hello-world.git //去掉遠(yuǎn)程倉庫關(guān)聯(lián)
$ git push -u origin master //將本地項(xiàng)目更新到github項(xiàng)目上去

gitconfig配置文件

     Git有一個工具被稱為git config,它允許你獲得和設(shè)置配置變量;這些變量可以控制Git的外觀和操作的各個方面。這些變量可以被存儲在三個不同的位置: 

     1./etc/gitconfig 文件:包含了適用于系統(tǒng)所有用戶和所有庫的值。如果你傳遞參數(shù)選項(xiàng)’--system’ 給 git config,它將明確的讀和寫這個文件。

     2.~/.gitconfig 文件 :具體到你的用戶。你可以通過傳遞--global 選項(xiàng)使Git 讀或?qū)戇@個特定的文件。

3.位于git目錄的config文件 (也就是 .git/config) :無論你當(dāng)前在用的庫是什么,特定指向該單一的庫。每個級別重寫前一個級別的值。因此,在.git/config中的值覆蓋了在/etc/gitconfig中的同一個值。

在Windows系統(tǒng)中,Git在HOME目錄中查找.gitconfig文件(對大多數(shù)人來說,位于C:\Documents and Settings\USER下)。它也會查找/etc/gitconfig,盡管它是相對于Msys 根目錄的。這可能是你在Windows中運(yùn)行安裝程序時決定安裝Git的任何地方。

配置相關(guān)信息:

2.1 當(dāng)你安裝Git后首先要做的事情是設(shè)置你的用戶名稱和e-mail地址。這是非常重要的,因?yàn)槊看蜧it提交都會使用該信息。它被永遠(yuǎn)的嵌入到了你的提交中:

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

2.2 你的編輯器(Your Editor)

現(xiàn)在,你的標(biāo)識已經(jīng)設(shè)置,你可以配置你的缺省文本編輯器,Git在需要你輸入一些消息時會使用該文本編輯器。缺省情況下,Git使用你的系統(tǒng)的缺省編輯器,這通??赡苁莢i 或者 vim。如果你想使用一個不同的文本編輯器,例如Emacs,你可以做如下操作:

$ git config --global core.editor emacs

2.3 檢查你的設(shè)置(Checking Your Settings)
如果你想檢查你的設(shè)置,你可以使用 git config --list 命令來列出Git可以在該處找到的所有的設(shè)置:

$ git config --list

你也可以查看Git認(rèn)為的一個特定的關(guān)鍵字目前的值,使用如下命令 git config {key}:

$ git config user.name

  2.4 獲取幫助(Getting help)

如果當(dāng)你在使用Git時需要幫助,有三種方法可以獲得任何git命令的手冊頁(manpage)幫助信息:

$ git help <verb>

$ git <verb> --help

$ man git-<verb>

例如,你可以運(yùn)行如下命令獲取對config命令的手冊頁幫助:

$ git help config

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容