解决git push问题

2020-05-02  本文已影响0人  xymspace
~:git push origin master

的时候,terminal报错没有权限。

unable to access ' https://git.coding.net/xxxx/xxxx.git/ ': The requested URL returned error: 403

  1. git 去找系统是否缓存了用户的密码有三种策略:去缓存中找,去磁盘中找,去钥匙串中找。

  2. /Users/xxx/.gitconfig 文件中(这个文件如果没设置过git 的全局配置可能会不存在),配置了git 到底选择哪个策略去找用户名和密码。

  3. 通过编辑 .gitconfig 文件,credential.helper = store/cache/osxkeychain 来修改 git 缓存策略。


方案一:

修改.git——>config的url
  1. 修改工程的.git 目录下的.config文件(url增加红字内容)
    [remote "origin"]
    url = https://用户名:密码@github.com/用户名/xxxx.git
  2. 命令行:
git push -u origin master
报错处理
错误一:
fatal: refusing to merge unrelated histories

命令行:

#如果是git pull,同理:
~:git pull origin master --allow-unrelated-histories
~:git push -u origin master -f
错误二:
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/XDGitHub/XMPPTool.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

命令行:

~:git push -u origin master -f

方案二:

重新配置本地的git个人信息

第一次git push origin master 时,不提示输入用户名和密码

查看本地的credential:

~:git help -a | grep credential

查看本地git全局配置:

~:git config --list

配置自己的git信息:

#配置git 的缺省编辑器
~:git config --global core.editor emacs

#配置git 的用户名和邮箱
~:git config --global user.name "xxxxxx"
~:git config --global user.email "xxxx@.com"

检查本地config

~:git config credential.helper

如果出现结果:

osxkeychain

需要删除该配置。命令行:

git config --show-origin --get credential.helper
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig    osxkeychain
~:open /Applications/Xcode.app/Contents/Developer/usr/share/git-core/

打开gitconfig,删除内容:

[credential]   helper = xxx

~:git config credential.helper
# 没有输出结果即删除本地缓存的用户名和密码生效

重新配置:

~:git  config --global  credential.helper  store
~:git  config --global  credential.helper  osxkeychain

执行命令:

git push -u origin master -f
上一篇 下一篇

猜你喜欢

热点阅读