git从github拉取分支更新本地代码

从此篇开始,转变风格,以后博客偶尔会附上一首歌。


前言

由于最近学习慕课的数据结构,在公司一台电脑,家里一台电脑,所以两边每天晚上不定更新代码到github上,遇到的问题就是每次都需要更新下远程仓库代码到本地,才可以解决push冲突的问题。在此记录一下。

具体操作

下面用到的是https协议,当然麻烦的是推送到远程仓库每次都需要手动填写用户名和密码,因为公司把22的ssh端口封掉了。
1.查看远程地址

$ git remote -v
origin  https://github.com/unlimitbladeworks/Data-Struts-Learning.git (fetch)
origin  https://github.com/unlimitbladeworks/Data-Struts-Learning.git (push)

2.fetch命令拉取远程仓库主分支,并且拉到本地temp作为暂存分支

$ git fetch origin master:temp
From https://github.com/unlimitbladeworks/Data-Struts-Learning
 * [new branch]      master     -> temp

3.查看当前指针指向的是哪个分支,*代表当前分支

$ git branch
* master
  temp

4.merge命令,将远程拉下来的temp分支与本地分支进行合并。

$ git merge temp
Merge made by the 'recursive' strategy.
 Chapter1-Array/README.md | 2 +-
 README.md                | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

5.版本合并统一后,push远程仓库代码,可以看到下面因为https协议,所以又让输了一遍用户名和密码

$ git push origin master
fatal: HttpRequestException encountered.
   发送请求时出错。
Username for 'https://github.com': [email protected]
Password for 'https://[email protected]@github.com':
Counting objects: 46, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (31/31), done.
Writing objects: 100% (46/46), 6.11 KiB | 782.00 KiB/s, done.
Total 46 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), completed with 5 local objects.
To https://github.com/unlimitbladeworks/Data-Struts-Learning.git
   7d407f3..6e6ede9  master -> master

6.删除暂存分支即可。

$ git branch -d temp
Deleted branch temp (was 7d407f3).

7.再次查看本地分支,已经删除,操作完毕。

$ git branch
* master

总结

总的来说以上7部,代码合并时不冲突就没有问题,这两天发现git真是太强大了…..之前虽然也有用过,不过只是皮毛操作而已….

猜你喜欢

转载自blog.csdn.net/s740556472/article/details/80087026