git基础和问题处理

配置用户名和邮箱

查看用户名和邮箱地址
$ git config user.name
$ git config user.email

修改用户名和邮箱地址
$ git config --global user.name "username"
$ git config --global user.email "email"

查看git配置
$ git config --list

提交本地代码到远程

进入工作目录
git init
git add .
git commit -m 'init commit'
//关联远程仓库
//git push <远程主机名> <本地分支名>:<远程分支名>
git push origin master:master
或者执行
git push -u origin master(默认将当前分支推送到远程master分支同时指定origin为默认主机,
后面就可以不加任何参数使用git push了)

问题

  1. error:src refspec master does not match any
    error: failed to push some refs to 'http://192.168.24.52:9010/monitor-plat/monitorplat.git'
    
    
    可能的原因:
    	本地文件与github上的文件有冲突
      本地需要提交的文件中存在空文件(可执行touch README)
      	解决方案:
      		touch README
      		git add README
      		git commit -m "change"
      		git push origin master
      本地的origin和remote origin/master 没有建立关联
      	解决方案:
      		git remote remove origin
      		git remote add origin git@github.com:XXX/XXX.github.io.git
      		git push origin master
      仓库名称不一样,导致远程和本地的仓库不能关联上
    		解决方案:
    			重命名当前分支: git branch -m oldBranchName newBranchName
    
    
    
  2. error: failed to push some refs to 'http://192.168.24.52:9010/monitor-plat/monitorplat-web.git'
    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.
    
    原因:远程文件不在本地代码目录中
    方案:
    可以通过如下命令进行代码合并【注:pull=fetch+merge]
    git pull --rebase origin master
    
  3. fatal:remote origin already exists
    原因:origin已经存在
    方案: git remote rm origin
    
  4. fatal: refusing to merge unrelated histories
    
    原因:不相关的分支相互合并
    
    方案:
    git pull origin master --allow-unrelated-histories
    

原因:不相关的分支相互合并

方案:
git pull origin master --allow-unrelated-histories



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值