git push被拒绝的处理方式

有时候我们使用git  push向远程仓库推送的时候,会报错如下:

[remote rejected] master -> master (branch is currently checked out)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To [email protected]:/var/git.server/.../web
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '[email protected]:/var/git.server/.../web'

这是因为git默认是拒绝push操作的,我们在.git/config里面添加如下配置项即可:

 [receive]
    denyCurrentBranch = ignore

这是当我们初始化一个远程仓库的时候,使用git  --bare  init即可了,而不是使用git  init,这样那么该远程仓库的目录下,也包含work  tree,当本地仓库向远程仓库push时,如果远程仓库正在push的分支上时,那么push后的结果不会反映在work  tree上,也就是在远程仓库的目录下对应的文件还是之前的内容,必须使用git  reset  --hard才能看到push之后的内容。

注意如果当时不在push的分支上,是没问题的。

时间: 2024-08-07 21:20:33

git push被拒绝的处理方式的相关文章

git push 提交报错 403 ,处理方式

今天在创建  git 仓库后,我试用 sourcetree 拉取仓库后, 创建了一个分支后,按照正常的操作提交新分支代码,但是报出了下面的错误内容: Pushing to https://github.com/J-Boos/J-Boss-Tool.gitremote: You must verify your email address.remote: See https://github.com/settings/emails.fatal: unable to access 'https://

git push 详细手册

git-push(1)手册页 目录位置:git安装位置/Git/mingw64/share/doc/git-doc/git-push.html  谷歌翻译了一下 名称 git-push-更新远程引用以及相关对象 概要 git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>] [--repo=<repository&

git 学习小记之记住https方式推送密码

昨天刚刚学了点git基础操作,但是不幸的是[email protected]给出公告说尽量使用 https 进行操作.可是在用 https 进行 push 时,都需要输入帐号和密码. 各种百度谷歌之后在[email protected]官网找到了解决方法<https方式使用[email protected]设置密码的方式>文中给出了几个方法,并且都非常简单. 关于 cache 缓存方式,我不太喜欢,因为要设置时间,而且会过期.而 store 相应的非常方便,设置全局后,方便多个库使用.当然如果

git push origin与git push -u origin master的区别

$ git push origin 上面命令表示,将当前分支推送到origin主机的对应分支. 如果当前分支只有一个追踪分支,那么主机名都可以省略. $ git push 如果当前分支与多个主机存在追踪关系,那么这个时候-u选项会指定一个默认主机,这样后面就可以不加任何参数使用git push. $ git push -u origin master 上面命令将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了. 不带任何参

git push

push就是把你本地仓储的commit传到远程仓储中去. 用法 git push <remote> <branch> push指定的分支到<remote>中去.  如果对于目标仓储来说不是一次fast-forward的merge, push会失败. 需要先git pull. git push <remote> --force 效果基本上和前一个命令相似, 但是他不管是不是fast-forward的merge都会push成功. 不建议使用这个命令. git p

让git push命令不再每次都输入密码

在每次使用git push的时候都需要输入用户和密码,是不是觉得很麻烦,为了提高效率 我们可以不需要输入密码就直接提交,我们知道Github获取远程库时,有ssh方式和https方式 两个方式的url地址不同,认证方式也不同.使用ssh时保存密钥对以后可以不再输入帐号密码, 而https却不能.所以如果想要不再输入帐号密码, 一种方式就是在git clone的时候使用ssh方式 另一种方式就是改变remote远程url,如下: $ git remote rm origin $ git remot

解决git Push时请求username和password,而不是ssh-key验证

转载自:https://blog.lowstz.org/posts/2011/11/23/why-git-push-require-username-password-github/ 之前开始用github时是在ubuntu下按着官方的新手指南搞定的.但最近一直在用fedora,所以也想在fedora下用github,配置的时候很顺利,就是在git push的每次都需要输入username和password,而我是配置好公钥登陆的.用ssh -T [email protected] 也是成功用公

02_创建Git仓库,克隆仓库,git add,git commit,git push,git pull,同行冲突,不同行冲突的结局方案,git mergetool的使用

1 创建Git资源库,残酷目录信息 创建git资源库的命令: git init –bare 仓库名称 (其中-bare表示的意思是空的库的意思) 进入E:\software\repository\git\itheima28,截图如下: hooks:提交一些脚本文件 info:存放一些个人信息,配置信息 objects:所有数据存放位置 refs:git指针信息,记录了修改了什么等的信息 config:核心的配置信息 description:描述信息 HEAD:存放的分支信息. 2 使用上面创建的

解决GitHub使用双因子身份认证“Two-Factor Athentication”后无法git push 代码的“fatal: Authentication failed for ...”错误

在GitHub上采取双因子身份认证后,在git push 的时候将会要求填写用户的用户名和密码,用户名就是用户在GitHub上申请的用户名,但是密码不是普通登录GitHub的密码. 一旦采取双因子身份认证,登录GitHub的时候既需要输入用户名和密码,还需要输入一个即时的验证码,这样可以对Git账户提供双重的安全保障.但是git push 却怎么也没法推送到远端repo,总是提示身份认证错误:“fatal: Authentication failed for ...” 查了很多国内的解决方案,只