目的是保持本地git和远程github上代码的同步。
参考官方教程
https://guides.github.com/activities/hello-world/
1.本地安装git和在github上注册账号
2.SHH认证及设置用户名和邮箱
为了保证安全,需要再本地生成秘钥,并把公共秘钥给远程github。
输入
ssh-keygen -t rsa
之后在 ~/.ssh/ 目录下可以看到 id_rsa 和 id_rsa.pub 两个文件。这两个就是 SSH Key 的秘钥对,其中,id_rsa 是私钥,不能泄露出去,id_rsa.pub 是公钥。
然后登陆 GitHub,上传 SSH Key 公钥
依次选择“Settings –> SSH and GPG keys –> New SSH key”,填上适当的 Title,并复制 id_rsa.pub 文件的内容粘贴在 Key 文本框里。
验证成功
ssh -T git@github.com
执行后提示:
Hi github! You’ve successfully authenticated, but GitHub does not provide shell access.
此时设置用户名和邮箱为注册Github时的名字
git config --global user.name “lukeyan”
git config --global user.email xxx@gmail.com
3.远程github网上新建一个仓库
设我的仓库名字为hellogithub
完成后
4.新建本地代码仓库
mkdir hellogithub
//向文件夹中添加.cpp文件,加入仓库
git add . //.表示全添加, git add README.md 表示只添加说明文件
//提交到仓库,这个版本名字叫
git commit -m "first commit"
5.提交本地代码到远程(同步)
按照以下格式提交到远程
git remote add origin git@github.com:yourgithubname/yourrepositoryname
git push -u origin master
比如我的仓库名为hellogithub,提交命令如下
add origin后面的网址就是你远程仓库的网址url。
git remote add origin https://github.com/QianFeifanhnu/githubhello.git/
如果git远程地址配错了,再次配置提示以下错误:
fatal: 远程 origin 已经存在
此时只需要将远程配置删除,重新添加即可;
git remote rm origin
然后
push -u origin master
origin master表示本地仓库。
如果出现
提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 ‘git pull …’)。
提示:详见 ‘git push –help’ 中的 ‘Note about fast-forwards’ 小节。
解决方式:
通过+master强行更新
解决
git push -u origin +master
发现远程仓库已经有最新的版本了
参考
http://www.2cto.com/kf/201704/623982.html
http://blog.csdn.net/ipatient/article/details/51334153
http://blog.csdn.net/jsu_9207/article/details/51803921
最后
以上就是大气小天鹅最近收集整理的关于Ubuntu创建Git仓库并上传到GitHub1.本地安装git和在github上注册账号2.SHH认证及设置用户名和邮箱3.远程github网上新建一个仓库4.新建本地代码仓库5.提交本地代码到远程(同步)的全部内容,更多相关Ubuntu创建Git仓库并上传到GitHub1内容请搜索靠谱客的其他文章。
发表评论 取消回复