git远程仓库,学习记录参考自廖雪峰老师的Git教程

 好记性不如烂笔头,做个记录,墙裂建议学习廖雪峰老师的Git教程,讲解得非常详细。

一、创建远程仓库并克隆仓库

第一步:本地创建秘钥:在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsaid_rsa.pub这两个文件,没有就创建,输入如下命令,一路回车即可创建。

toohoo@ubuntu:~$ ssh-keygen -t rsa -C "youremailexample@host.com"

第二步:关联本地仓库和远程仓库

toohoo@ubuntu:~/django$  git remote add origin git@github.com:too-hoo/django.git

注意:在创建远程仓库的时候,不要点Initialize this repository with a README,不要创建readme文件先,否则,本地要push代码上去就会报错:

The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
To github.com:too-hoo/django.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:too-hoo/django.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 此时如果使用命令 $ git pull --rebase origin master 时会包错:

toohoo@ubuntu:~/django$ git pull --rebase origin master
error: cannot pull with rebase: Your index contains uncommitted changes.
error: please commit or stash them.

原因是本地有未提交的更改,是不能git pull的

解决方法:如下所示

①先执行git stash ②再执行git pull --rebase origin master ③最后再执行git stash pop

git stash           #可用来暂存当前正在进行的工作
git stash pop   #从Git栈中读取最近一次保存的内容

toohoo@ubuntu:~/django$ git stash
Saved working directory and index state WIP on master: 3869a48 add test.txt
toohoo@ubuntu:~/django$ git pull --rebase origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:too-hoo/django
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: wrote a readme file
Applying: add 3 files.
Applying: add distributed
Applying: append GPL
Applying: understand how stage works
Applying: git tracks changes
Applying: 第二次修改提交
Applying: add test.txt
Applying: remove test.txt
Applying: add test.txt
toohoo@ubuntu:~/django$ ls
file1.txt  file2.txt  file3.txt  LICENSE  README.md  readme.txt  test.txt
toohoo@ubuntu:~/django$ git stash pop
Removing test.txt
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	deleted:    test.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (330316e76671bb61e7d72154a67125abb8a0a078)

以上原因就是ÿ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值