git本地仓库首次push到远程仓库出现错误 ! [rejected] master -> master (fetch first)

新建好本地的仓库和远程仓库之后,

经过git add . ,然后git commit -m "......",

最后想推送到远程仓库的时候git push -u origin master,出现下图错误

! [rejected]        master -> master (fetch first)

error: failed to push some refs to

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 push -f origin master

附上git push 的说明

NAME

git-push - Update remote refs along with associated objects

SYNOPSIS

git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
	   [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose]
	   [-u | --set-upstream]
	   [--[no-]signed|--sign=(true|false|if-asked)]
	   [--force-with-lease[=<refname>[:<expect>]]]
	   [--no-verify] [<repository> [<refspec>…?]]

-f  --force

Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected.

This flag disables these checks, and can cause the remote repository to lose commits; use it with care.

Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.*.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch). See the<refspec>... section above for details.

时间: 2024-08-21 15:34:33

git本地仓库首次push到远程仓库出现错误 ! [rejected] master -> master (fetch first)的相关文章

Git本地已有项目关联远程仓库

情况: 本地已有项目 远程有个仓库 目的: 本地项目关联远程仓库 首先要把本地项目变成git管理的,也就是建立一个本地仓库,可以在项目目录下面使用git init命令初始化仓库,初始化成功之后会在仓库里面看到 一个.git文件 .git文件里面记录仓库的历史信息,版本分支等等. 然后我们在gitee上新建一个仓库tools去关联它,这里需要把本地的ssh公钥添加到gitee,本地公钥在C:\Users\西红柿\.ssh下面的id_rsa.pub文件, 注意id_rsa文件是私钥,不要透露给别人.

git笔记之eclipse使用github远程仓库进行版本管理

这里记录一下eclipse开发工具中git的使用说明. 环境:centOS,eclipse-jee-kepler-SR2-linux-gtk-x86_64.tar.gz eclipse的使用需要依赖Java环境,这边CentOS系统里面已经安装好了JDK: 不能使用open-jdk,此版本会出现不明异常. 1.eclipse安装egit插件: eclipse里面,help --> Eclipse Marketplace 搜索egit 按照eclipse默认要求一步一步安装即可. 2.New Pr

解决git push至远程仓库失败的问题

产生问题的原因: 远程仓库存在本地不存在的文件, 一个常见的例子是创建repository时勾选了README.md, 但此时本地还没有这个文件, 就会导致本地文件无法同步到远程仓库的问题. 解决方法: 在git push至远程仓库之前, 先将远程仓库文件同步至本地. 执行下面命令 git pull --rebase origin master 原文地址:https://www.cnblogs.com/shaohsiung/p/9535934.html

使用git命令将本地项目推送到远程仓库

将本地项目推送到远程仓库 这里先放一张图, 有助于理解git命令 1. 在GitHub上新建一个仓库 注意不要勾选自动生成README.md文件, 否则会产生某些问题, README.md文件到时可以在本地项目文件夹内创新好, 再同步到远程仓库 2. 创建一个存储项目的文件夹, 并进入文件夹下 3.创建本地仓库 git init 4. 创建README.md 5. 同步远程仓库git remote add origin 'HTTPS' 备注: 'HTTPS'替换为仓库链接 6. 添加到Index

git仓库迁移和更新远程仓库地址

一.git仓库迁移 1,从原仓库clone或pull到本地仓库 git clone project_name ?[old_remote_repository_address] 2,?在新的git创建一个新仓库.如果用gitolite搭建的git服务器,那么只需要在配置文件gitolite.conf上添加仓库和用户,然后push到服务器即可. 3,进入clone下来的本地仓库目录,将远程仓库地址修改为新的远程仓库地址 project_name> git remote remove origin p

小蚂蚁学习git(2)——Git撤销修改和删除,远程仓库的创建推送和克隆

接上篇(http://my.oschina.net/woshixiaomayi/blog/521265)继续写. 四.Git撤销修改和删除 1.撤销修改 场景:在readme.txt中添加了一段话"今天天气不错".在还未提交之前,发现这句话写的不对,那么有一下几种方式修改:1.直接动手删除掉那些错误的内容,然后再用add添加到暂存区,在commit提交到分支.2.按照上一篇所讲到的使用命令 git reset -hard  HEAD^ 回退到上一个版本.除了昨天说的这两个方法之外,还有

源代码管理——git(分布式版本控制和集中式版本控制对比,git和SVN对比,git常用指令,搭建GitHub远程仓库,搭建oschina远程仓库 )

一.git简介 什么是git? git是一款开源的分布式版本控制工具 在世界上所有的分布式版本控制工具中,git是最快.最简单.最流行的 git的起源 作者是Linux之父:Linus Benedict Torvalds 当初开发git仅仅是为了辅助Linux内核的开发(管理源代码) git的现状 在国外已经非常普及,国内并未普及(在慢慢普及) 越来越多的开源项目已经转移到git CVS 最早的开源.免费的集中式版本控制工具 自身设计有问题,会造成提交文件不完整,版本库莫名其妙损坏的情况 SVN

20180618_在githhub上创建远程仓库,再克隆远程仓库的代码

在githhub上创建远程仓库,再克隆远程仓库的代码 感谢廖雪峰老师提供的git教程: 传送门: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 先有本地库,后有远程库的时候,如何关联远程库. 现在,假设我们从零开发,那么最好的方式是先创建远程库,然后,从远程库克隆. 首先,登陆GitHub,创建一个新的仓库,名字叫gitskills: 我们勾选Initialize this

git将本地仓库上传到远程仓库

在已有的Git库中搭建新库,并且将本地的git仓库,上传到远程服务器的git库中,从而开始一个新的项目 首先,在本地新建文件夹abc,进入到abc里面,然后git init.这样就在本地初始化了一个git项目abc. 然后,登录到远程的git服务器上,到gitrepo目录下面,mkdir abc.git.然后进入abc.git目录.git  --bare init.这样就在服务器端建立了一个空的git项目. 之后,在本地,进入到abc目录里面,增加远程仓库.git remote -v 显示项目目