github 入门

来源:互联网 发布:ppt mac版下载 编辑:程序博客网 时间:2024/06/05 12:45

环境 ubuntu 16.04
git version 2.7.4

#安装Gitwen@wen:~$ sudo apt-get install git  #生成ssh密钥wen@wen:~$ ssh-keygen -t rsa -C "865015063@qq.com"#wen@wen:~$ nautilus .ssh#测试链接wen@wen:~$ ssh -T git@github.com#配置Git的配置文件,username和email:git config --global user.name "your name"   //配置用户名  git config --global user.email "your email" //配置email   

上传库

#创建测试目录wen@wen:~$ mkdir runoobwen@wen:~$ cd runoob#创建文件wen@wen:~/runoob$ echo "#菜鸟哦啊测试" >> README.md#初始化wen@wen:~/runoob$ git init#选择要添加进仓库的文件:(所有 add . )wen@wen:~/runoob$ git add README.md#添加备注wen@wen:~/runoob$ git commit -m "添加 README.md 文件"#上传#git remote add origin git@github.com:XXX/XXX.gitwen@wen:~/runoob$ git remote add origin https://github.com/wenjayliu/runoob.gitwen@wen:~/runoob$ git push -u origin master

本地更新修改

$ git fetch origin
$ git merge origin/masterUpdating 0205aab..febd8edFast-forward README.md | 1 + 1 file changed, 1 insertion(+)

一些可能遇到的问题解决:

如果输入
$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git
提示出错信息:
fatal: remote origin already exists.

解决办法如下:
1、先输入
$ git remote rm origin

2、再输入
gitremoteaddorigingit@github.com:djqiang/gitdemo.git3 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”]那一行删掉就好了!
如果输入
sshTgit@github.comPermissiondenied(publickey).keysshgithub1 ssh-agent,
再输入
sshadd /.ssh/idkey2sshadd /.ssh/idkeyCouldnotopenaconnectiontoyourauthenticationagent.keyGitGuisshkeysshsshaddusertoken3idrsa.pub git push origin master
提示出错信息:error:failed to push som refs to …….
解决办法如下:
1、先输入gitpulloriginmaster//github2 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、则需要重新输入
gitremoteaddorigingit@github.com:djqiang/gitdemo.git使git makdir ~/hello-world //创建一个项目hello-world
cd /helloworld// git init //初始化
touchREADME git add README //更新README文件
gitcommitmfirstcommit//firstcommit git remote add origin git@github.com:defnngj/hello-world.git //连接远程github项目
$ git push -u origin master //将本地项目更新到github项目上去

0 0