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 [email protected]

  3、生成密钥

$ ssh-keygen -t rsa -C "[email protected]" //邮箱同上

  4、提交密钥

vim /home/linx/.ssh/id_rsa.pub //复制里面的密钥

  到github网页中登陆自己的账号,然后再account setting中,找到SSH KEY讲复制的密钥加入(需要再次输入github的密码)

  5、检验是否链接上了github

$ ssh [email protected]

//正常情况下,回显如下

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 [email protected]: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

  目前了解到的也就这三个问题了。

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

 转载:http://www.cnblogs.com/plinx/archive/2013/04/08/3009159.html

 

[root@localhost Jessica]# mkdir tmp

[root@localhost Jessica]# cd tmp

[root@localhost tmp]# git init

Initialized empty Git repository in /root/Jessica/Jessica/tmp/.git/

[root@localhost tmp]# touch README

[root@localhost tmp]# git add README 

[root@localhost tmp]# vim README 

[root@localhost tmp]# vim myfile.txt

[root@localhost tmp]# git add .

[root@localhost tmp]# git commit -m 'first commit'

[master (root-commit) 4fc0345] first commit

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 README

 create mode 100644 myfile.txt

[root@localhost tmp]# git remote add origin [email protected]:Jessicahust/tmp.git

[root@localhost tmp]# git push -u origin master

ERROR: Repository not found.

fatal: The remote end hung up unexpectedly

[root@localhost tmp]# git push -u origin master

To [email protected]:Jessicahust/tmp.git

 ! [rejected]        master -> master (non-fast-forward)

error: failed to push some refs to '[email protected]:Jessicahust/tmp.git'

To prevent you from losing history, non-fast-forward updates were rejected

Merge the remote changes before pushing again.  See the 'Note about

fast-forwards' section of 'git push --help' for details.

[root@localhost tmp]# git push -f

Counting objects: 4, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (4/4), 269 bytes, done.

Total 4 (delta 0), reused 0 (delta 0)

To [email protected]:Jessicahust/tmp.git

 + ae65e0f...4fc0345 master -> master (forced update)

[root@localhost tmp]# git clone https://github.com/Jessicahust/tmp.git

Initialized empty Git repository in /root/Jessica/Jessica/tmp/tmp/.git/

remote: Counting objects: 4, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 4 (delta 0), reused 4 (delta 0)

Unpacking objects: 100% (4/4), done.

[root@localhost tmp]# cd tmp/

[root@localhost tmp]# ll

总用量 4

-rw-r--r--. 1 root root 12 12月 19 17:38 myfile.txt

-rw-r--r--. 1 root root  0 12月 19 17:38 README

[root@localhost tmp]# vim myfile.txt 

[root@localhost tmp]# git push -u origin master

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/Jessicahust/tmp.git/info/refs



fatal: HTTP request failed

[root@localhost tmp]# git remote rm origin

[root@localhost tmp]# git push -u origin master

fatal: 'origin' does not appear to be a git repository

fatal: The remote end hung up unexpectedly

[root@localhost tmp]# git push -u origin master

fatal: 'origin' does not appear to be a git repository

fatal: The remote end hung up unexpectedly

[root@localhost tmp]# git commit -m 'second commit'

# On branch master

# Changed but not updated:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#    modified:   myfile.txt

#

no changes added to commit (use "git add" and/or "git commit -a")

[root@localhost tmp]# git remote add origin [email protected]:Jessicahust/tmp.git

[root@localhost tmp]# git push -u origin master

Branch master set up to track remote branch master from origin.

Everything up-to-date

[root@localhost tmp]# vim myfile.txt 

[root@localhost tmp]# git add .

[root@localhost tmp]# git commit -m 'second commit'

[master 68d8831] second commit

 1 files changed, 1 insertions(+), 1 deletions(-)

[root@localhost tmp]# git push -u origin master

Counting objects: 5, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 295 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To [email protected]:Jessicahust/tmp.git

   4fc0345..68d8831  master -> master

Branch master set up to track remote branch master from origin.

 将自己的githubpull下来修改了传送

[root@localhost vimide]# git clone https://github.com/Jessicahust/vimide.git

Initialized empty Git repository in /root/vimide/vimide/vimide/.git/

remote: Counting objects: 9, done.

remote: Compressing objects: 100% (6/6), done.

remote: Total 9 (delta 1), reused 6 (delta 1), pack-reused 0

Unpacking objects: 100% (9/9), done.

[root@localhost vimide]# git add bundle

[root@localhost vimide]# git commit -m 'first commit'

# On branch master

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#    vimide/

nothing added to commit but untracked files present (use "git add" to track)

[root@localhost vimide]# git init 

Reinitialized existing Git repository in /root/vimide/vimide/.git/

[root@localhost vimide]# git add README

[root@localhost vimide]# git add bundle

[root@localhost vimide]# git add .\

> ^C

[root@localhost vimide]# git add .

[root@localhost vimide]# git commit -m 'second commit'

[master 427c834] second commit

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 160000 vimide

[root@localhost vimide]# git remote add origin [email protected]:Jessicahust/vimide.git

fatal: remote origin already exists.

[root@localhost vimide]# git remote rm origin

[root@localhost vimide]# git remote add origin [email protected]:Jessicahust/vimide.git

[root@localhost vimide]# git push -u origin master

Counting objects: 3, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (2/2), 264 bytes, done.

Total 2 (delta 1), reused 0 (delta 0)

To [email protected]:Jessicahust/vimide.git

   70d526e..427c834  master -> master

Branch master set up to track remote branch master from origin.

 

你可能感兴趣的:(github)