Git鏈接到自己的Github(1)簡單的開始


  好長時間沒上來弄東西了,今天回來先開始弄下Git,之后再繼續寫uboot與kernel的編譯,在版本控制下更加宏觀地觀察每次的變化。

 

  1、在ubuntu中安裝git

$ sudo apt-get install git git-core

  2、配置本機的git

$ git config --global user.name "abcd"
$ git config --global user.email abcd@efgh.com

  3、生成密鑰

$ ssh-keygen -t rsa -C "abcd@efgh.com" //郵箱同上

  4、提交密鑰

vim /home/linx/.ssh/id_rsa.pub //復制里面的密鑰

  到github網頁中登陸自己的賬號,然后再account setting中,找到SSH KEY講復制的密鑰加入(需要再次輸入github的密碼)

  5、檢驗是否鏈接上了github

$ ssh git@github.com
//正常情況下,回顯如下
PTY allocation request failed on channel 0
Hi plinx! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

  6、首次推送

$ mkdir tmp      //創建推送目錄
$ cd tmp         //進入推送目錄    
$ git init       //設置該目錄為推送
$ touch README   //生成readme
$ git add README //加入修改列表
$ git commit -m 'first commit' //遞交修改聲明
$ git remote add origin git@github.com:abcd/tmp.git //為遠程Git更名為origin
$ git push -u origin master //推送此次修改

  然后各種問題從這里開始了,以下談一下解決的方法:

 

  問題一:

ERROR: Repository not found.

  這個問題是因為在你推送的github賬戶中,並沒有這個Repository。

  解決方法:

  1)檢查自己的github中的Repository,檢查自己創建的目錄,必須要兩者一致;

  2)先git clone下github中的Repository,然后再進行更改,這樣就一定一致了。

  問題二:

Agent admitted failure to sign using the key. 
Permission denied (publickey)

  這個問題是因為你的ssh key並沒有加入到你想git的github賬戶的ssh key中,所以沒有訪問權限。

  解決方法:

  1)重新拷貝一份當前的~/.ssh/id_rsa.pub中的ssh key到github中添加;

  2)先刪除~/.ssh/in_rsa*文件,然后重新ssh-keygen一份sshkey來生成密鑰,然后復制到github,接着ssh鏈接github來檢驗是否成功聯通。

  問題三:

//出現如下提示
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ...

  這個問題是因為,github中已經有了這個代碼,不允許你覆蓋它。

  解決方法:

  1)強制推送,一般不推薦!

$ git push -f

  2)

$ git pull

  然后將出現其他提示,具體意思是說branch與merge未指定,git無法選擇要推送的分支。

  可以通過修改 .git/config文件中的下列內容

[branch "master"]
    remote = origin
    merge = refs/heads/master

  也可以直接命令行修改

$ git config branch.master.remote origin
$ git config branch.master.merge ref/heads/master

  目前了解到的也就這三個問題了。

  之后就可以成功得推送了。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM