您的位置:首页 > 编程语言

推送仓库到github

2016-12-02 15:36 204 查看
步骤1、首先在本地创建ssh key

$ ssh-keygen -t rsa -C "your_email@youremail.com"  

后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key,这个是在ubuntu系统下的情况,在windows系统,密匙默认生成位置:/c/Users/你的用户名/.ssh/id_rsa

步骤2、回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。为了验证是否成功,在Git bash下输入:

$ ssh -T git@github.com  

如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does
not provide shell access 。这就表示已成功连上github

步骤3、接下来还需要设置username和email,因为github每次commit都会记录他们

$ git config --global user.name "your name"  

$ git config --global user.email "your_email@youremail.com"  

然后在github上创建一个仓库加入名为:repo.git ,下面的步骤4、5根据你自己目前的情况选择一种就行

步骤4、如果你在本地还没有创建仓库,进入想创建为仓库的目录,在git的命令行中输入:

echo "# srs_record" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:your_name/repo.git
git push -u origin master

  

步骤5、如果在本地已经创建好仓库,进入仓库目录:

  

git remote add origin git@github.com:your_name/repo.git
git push -u origin master


 
这一步相比较第4步,就是少了创建本地仓库这一步

  有时虽然在本地创建了一个仓库,但是仓库为空,会报:error: src refspec master does not match any的错误,引起该错误的原因是,目录中没有文     件,空目录是不能提交上去的,在本地仓库增加一个文件,使得仓库不为空即可

说明,这里推送仓库到github的方式,总的来说就是,先在github上创建一个仓库,然后在本地创建一个仓库,再执行步骤4、步骤5。

参考:
http://blog.csdn.net/bj123467/article/details/52981009 https://help.github.com/articles/adding-a-remote/ http://forum.xda-developers.com/showthread.php?t=1877040
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: