- $ git push origin master
- To git@192.168.1.3:k6.git
- ! [rejected] master -> master (non-fast-forward)
- error: failed to push some refs to 'git@192.168.1.3:k6.git'
- To prevent you from losing history, non-fast-forward updates were rejected
- Merge the remote changes before pushing again. See the 'Note about
- fast-forwards' section of 'git push --help' for details.
- cbk@YCS:~/work/k6_130708/k6$ git fecth
- git: 'fecth' is not a git command. See 'git --help'.
git push 错误,因为没有先pull最新的代码,需要以下操作:
- $ git fetch origin
- $ git merge origin/master
- $ git push origin master
如果安装git后没有设置你的用户名称和e-mail地址,还需要先执行:
- $ git config --global user.name "cbk"
- $ git config --global user.email <a href="mailto:cbk@ylf.com">cbk@ylf.com</a>
这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:
重申一遍,你只需要做一次这个设置。如果你传递了 --global 选项,因为Git将总是会使用该信息来处理你在系统中所做的一切操作。如果你希望在一个特定的项目中使用不同的名称或e-mail地址,你可以在该项目中运行该命令而不要--global选项。
具体到此问题,如果没有设置你的用户名称和e-mail地址,则一直正确无法push代码。
- 上一篇:git config配置文件
当要push代码到git时,出现提示:
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
- $ git push origin master
- To ../remote/
- ! [rejected] master -> master (non-fast forward)
- error: failed to push some refs to '../remote/'
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.
问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f
2,先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于- $ git pull
可是,这时候又出现了如下的问题:
上面出现的 [branch "master"]是需要明确(.git/config)如下的内容[branch "master"]
remote = origin
merge = refs/heads/master
这等于告诉git2件事:1,当你处于master branch, 默认的remote就是origin。
2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:
- $ git config branch.master.remote origin
- $ git config branch.master.merge refs/heads/master
之后再重新git pull下。最后git push你的代码吧。it works now~
相关推荐
Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe
最新版的git安装包(Git-2.13.2-64-bit)
windows xp git安装包 Git-2.10.0-32-bit,支持Windows XP 32位系统
git-lfs-windows-v3.2.0.exe
git 管理工具 Git-2.21.0-64-bit安装包.rar
Git-2.23.0-64-bit.zip
Git-2.12.0-64-bit 64位下载
git-2.41.0-64-bit window版本下载
Git-2.33.1-64-bit和Git-2.28.0-64-bit.exe
Git-2.28.0-64-bit git安装包windos64位官方下载 需要的自取
Git-2.14.1-64-bit.zip
Git-2.34.0-64-bit安装包
Git-2.10.0-32-bit_++++_TortoiseGit-1.8.16.0-32bit.rar 自己使用
Git-2.40.0-64-bit.exe Git是一个免费的开源分布式版本控制系统,可以快速高效地处理从小到大的所有项目。Git易于学习,占用空间小,性能却非常快。它超越了像Subversion、CVS、Perforce和ClearCase这样的配置管理...
Windows Git 2.10.2 64-bit
Git-2.30.0-64-bit Git-2.30.0-64-bit Git-2.30.0-64-bit Git-2.30.0-64-bit
安装完成后,在开始菜单里找到“Git”->“Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功! 安装完成后,还需要最后一步设置,在命令行输入: $ git config --global user.name "Your Name" $ git ...
git-2.10.0-64-bit.exe 安装包,适合window 64位系统,可视化界面
你下载最新的(2.15.0)的Windows 64位版本的Git。这是最近维护的构建。这是17天前发布的,在2017-10-30。
Git安装包快速下载;git资源包,Git下载,Git压缩包;Git工具下载;Git-2.21.0-64-bit.zip;Git工具下载