Git学习笔记;Git bash 库同步问题

前言

在使用GitHub管理自己的版本库时遇到了问题,光是解决了容易忘,于是写下帖子,方便后来人也便于自己回忆。

问题

push本地代码到github出错
刚创建的github版本库,在push代码时出错:

$ git push -u origin master
To [email protected]:******/Demo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

网上搜索了下,是因为远程repository和我本地的repository冲突导致的,而我在创建版本库后,是现在本地创建了版本库,并没有和网络的先同步,应该先把网上的东西pull下来。

解决方法:

1.使用强制push的方法:

$ git push -u origin master -f 

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

2.push前先将远程repository修改pull下来

$ git pull origin master

$ git push -u origin master

3.若不想merge远程和本地修改,可以先创建新的分支:

$ git branch [name]

然后push

$ git push -u origin [name]

猜你喜欢

转载自blog.csdn.net/lvsehaiyang1993/article/details/80842152