将本地其他项目推送到git仓库

本文详细介绍了如何解除本地git仓库的绑定,重新初始化,并将本地仓库与远程仓库关联。同时,针对git分支不一致的情况,演示了如何修改本地分支名称,并将更改提交到远程仓库。在推送过程中遇到的错误提示,提供了解决方案,包括git pull合并远程仓库的变更。此教程适合git初学者和开发者进行日常版本控制操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 解除本地仓库git的绑定;

     rm -rf .git
    
  2. 初始化git

      git init
    
  3. 方便起见如果git仓库的分支与本地分支不一致(比如git分支式main本地master),将本地分支改为main

    git branch -m main
    
  4. 添加文件到暂存区

    git add .
    
  5. 暂存区中的内容提交到本地仓库

    	 git commit -m '说明文字'
    
  6. 复制git仓库地址并将本地仓库关联自己的远程仓库

      git remote add origin 复制的远程git仓库地址
    
  7. 推送到远程仓库

    git push --set-upstream origin mian
    
  8. 报错: error: src refspec mian does not match any
    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 pull origin main --allow-unrelated-histories From https://github.com/*********(远程仓库地址)
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值