【git】阿里云上传代码到github附SSH-KEY免密码上传&更新github代码到本地
2017-06-19 12:40
656 查看
远程连接阿里云服务器,确保安全组内ssh端口打开(如果更改ssh连接端口的话),按照下面代码依次敲
键入https://github.com/
再刷新页面— OK
上述方式每次都需要输入用户名和密码。
下面的方法设置免密码上传代码:
依次键入
把对应的ssh-key复制到对应区域
然后键入:
配置成功之后:
刷新页面:
更新github代码到本地
我们在github上修改代码:然后点击下面的绿色的提交按钮。
git bash中键入:
OK
root用户下登录 [root@iz2ze8w7169ei61c5c1il5z /]cd ~ [root@iz2ze8w7169ei61c5c1il5z ~]mkdir git-demo [root@iz2ze8w7169ei61c5c1il5z ~]cd git-demo [root@iz2ze8w7169ei61c5c1il5z git-demo]git init [root@iz2ze8w7169ei61c5c1il5z git-demo]# git init Reinitialized existing Git repository in /root/git-demo/.git/ [root@iz2ze8w7169ei61c5c1il5z git-demo]# echo 'Hello World' >README.MD [root@iz2ze8w7169ei61c5c1il5z git-demo]# ll -a total 16 drwxr-xr-x 3 root root 4096 Jun 19 11:06 . drwxr-xr-x 4 root root 4096 Jun 16 16:51 .. drwxr-xr-x 8 root root 4096 Jun 19 11:04 .git -rw-r--r-- 1 root root 12 Jun 19 11:06 README.MD [root@iz2ze8w7169ei61c5c1il5z git-demo]# more README.MD Hello World [root@iz2ze8w7169ei61c5c1il5z git-demo]# git add . [root@iz2ze8w7169ei61c5c1il5z git-demo]# git commit -m "first commit"
键入https://github.com/
[root@iz2ze8w7169ei61c5c1il5z git-demo]# git remote add first https://github.com/Drzhu/test.git first可随意指定,后面对应即可 [root@iz2ze8w7169ei61c5c1il5z git-demo]# git push -u first master Username for 'https://github.com': Drzhu Password for 'https://Drzhu@github.com': Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (5/5), 434 bytes | 0 bytes/s, done. Total 5 (delta 0), reused 0 (delta 0) To https://github.com/Drzhu/test.git * [new branch] master -> master Branch master set up to track remote branch master from first.
再刷新页面— OK
上述方式每次都需要输入用户名和密码。
下面的方法设置免密码上传代码:
依次键入
ssh-keygen -t rsa -C "your_email@youremail.com" //邮箱地址为github上注册的邮箱 之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key [root@iz2ze8w7169ei61c5c1il5z git-demo]# more ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDWf+/pDrURgdmKdXxgI+D4+I6QQpS/2UF7mgth5PbDMOaEZ7o7XEtWq9Sa2IxkVumXdDt7wb8/JYcKPiQWaJ70PGVqzxjeKRy3VEaOSRJ78PzY0QYVby3xuiKOqJMTgOVdpgt8Z1IGOeYY08TYb9xjSHLrzTCRVzZTjLZjtEJLG0xCAK+THHIERTYxtuYrSisqtTl8MscN+kJCX7IIt5O51duEVzmycXsD3u/Noc 3yRqzgwmECg7dt+gs6W6opu9yAmub0p/p4GpYH36DjnRYByFTgQ6IAsyi+jvx+kz6Op3wiQs/cicVYY1QHZCCQQjfPDylqxE8iGa+otC6qMbZj your_email@youremail.com
把对应的ssh-key复制到对应区域
然后键入:
ssh -T git@github.com 如果是第一次的会提示是否continue,输入yes就会看到:You've successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。 然后配置你的全局变量 git config --global user.name "your name" git config --global user.email "your_email@youremail.com" [root@iz2ze8w7169ei61c5c1il5z git-demo]# git config --list 查看你的全局参数列表
配置成功之后:
[root@iz2ze8w7169ei61c5c1il5z git-demo]# git remote add nologin git@github.com:Drzhu/test.git//无需输入用户名和密码,表示配置成功 [root@iz2ze8w7169ei61c5c1il5z git-demo]# git remote -v first https://github.com/Drzhu/test.git (fetch) first https://github.com/Drzhu/test.git (push) nologin git@github.com:Drzhu/test.git (fetch) nologin git@github.com:Drzhu/test.git (push) 显示有两个远程连接,配置成功 下面进行验证: [root@iz2ze8w7169ei61c5c1il5z git-demo]# echo "my name is nologin" > README.MD [root@iz2ze8w7169ei61c5c1il5z git-demo]# git add . [root@iz2ze8w7169ei61c5c1il5z git-demo]# git commit -m "i am nologin" [master 7c1b386] i am nologin 1 file changed, 1 insertion(+), 1 deletion(-) [root@iz2ze8w7169ei61c5c1il5z git-demo]# git push -u nologin master Counting objects: 3, done. Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@github.com:Drzhu/test.git 0908acf..7c1b386 master -> master Branch master set up to track remote branch master from nologin.
刷新页面:
更新github代码到本地
我们在github上修改代码:然后点击下面的绿色的提交按钮。
git bash中键入:
[root@iz2ze8w7169ei61c5c1il5z git-demo]# git fetch nologin master:temp-nologin remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From github.com:Drzhu/test * [new branch] master -> temp-nologin 7c1b386..269aafe master -> nologin/master [root@iz2ze8w7169ei61c5c1il5z git-demo]# git branch * master temp-nologin [root@iz2ze8w7169ei61c5c1il5z git-demo]# more README.MD my name is nologin [root@iz2ze8w7169ei61c5c1il5z git-demo]# git checkout temp-nologin Switched to branch 'temp-nologin' [root@iz2ze8w7169ei61c5c1il5z git-demo]# more README.MD my name is nologin<br/> had changed in github [root@iz2ze8w7169ei61c5c1il5z git-demo]# git checkout master Switched to branch 'master' [root@iz2ze8w7169ei61c5c1il5z git-demo]# git merge temp-nologin Updating 7c1b386..269aafe Fast-forward README.MD | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) [root@iz2ze8w7169ei61c5c1il5z git-demo]# more README.MD my name is nologin<br/> had changed in github
OK
相关文章推荐
- git上传本地代码到github(最简单方法,不用配置ssh)
- 使用Git将本地代码上传到GitHub
- git托管代码随笔--运用ssh传输,不用每次提交频繁输入github账号密码
- 阿里云centos和本地windows实现git代码管理(github仓储)
- 本地代码上传 -&gt; Github
- 【git】利用git将本地代码上传到github
- 【GIT】Github上传本地代码详解
- git&github使用笔记(一)——Git建立本地库,并上传Github
- 如何用git命令行上传本地代码到github
- 怎么用git bash上传本地项目代码到您的github仓库1
- 使用git上传代码到github<一>
- git使用之如何将github库下载到本地与如何将代码上传github
- 笔记:Git Bash ssh key配置及首次提交本地工程到github(Windows )
- 如何用git命令行上传本地代码到github
- git使用之如何将github库下载到本地与如何将代码上传github
- git使用之如何将github库下载到本地与如何将代码上传github
- 使用Git上传本地项目代码到github
- 在终端下使用Git上传本地代码至GitHub
- git命令及使用/上传或更新代码到github
- Git本地项目上传 & SourceTree & GitHub 简单使用