作者:无 | 来源:互联网 | 2023-09-09 11:37
新建好本地的仓库和远程仓库之后,经过gitadd.,然后gitcommit-m,最后想推送到远程仓库的时候gitpush-uoriginmaster,出现下图错误!
新建好本地的仓库和远程仓库之后,
经过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=]
[--repo=] [-f | --force] [--prune] [-v | --verbose]
[-u | --set-upstream]
[--[no-]signed|--sign=(true|false|if-asked)]
[--force-with-lease[=[:]]]
[--no-verify] [ […?]]
-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...
section above for details.
master (fetch first),mamicode.com" target="_blank">git本地仓库首次push到远程仓库出现错误 ! [rejected] master -> master (fetch first)