华为云Git仓库操作,将本地代码上传到CodeHub

本文介绍了如何在华为云DevCloud使用Git将本地代码上传到CodeHub,包括创建空仓库、设置gitignore、迁移SVN代码、基本git操作(初始化、添加提交、远程仓库配置)及常见问题解决方案。
摘要由CSDN通过智能技术生成

华为云Git将本地代码上传到CodeHub

在DevCloud代码托管服务中,创建一个空仓库

不选择“选择gitignore”。

勾选“允许生成README文件”。

在本地,准备好将要上传的源代码。

如果原来是来自SVN服务器的,建议参考 将SVN代码库迁移到Git代码库

如果原来没有纳入过任何的版本系统,则在源代码的根目录,执行以下git命令(以Git Bash为例):

  1. 初始化Git仓库
git init
  1. 将文件加入版本库
git add *

# *表示讲当前文件夹下所有add到版本库
  1. 创建初始提交:
git commit -m "init commit"
  1. 设置本地仓库的远程服务器地址:
  • 如果原来从其它地方clone的git仓库,则添加一个新的remote,命令行参考如下:
git remote add new git@***.***.com:testtransfer/Repo1.git      ——(new 后面为仓库地址)

  • 如果是一个刚刚初始化的仓库,则添加一个名为origin的remote,命令行参考如下:
git remote add origin git@***.***.com:testtransfer/Repo1.git    ——(origin 后面为仓库地址)

  1. 推送全部代码到远端仓库:
git push new master      (对应步骤3的第一种情况)

git push origin master   (对应步骤3的第二种情况)

容易遇见的问题

1、问题1

error: failed to push some refs to 'git@github.com:yangchao0718/cocos2d.git
hint: Updates were rejected because the tip of your current branch is behin
hint: its remote counterpart. Integrate the remote changes

解决:

git pull --rebase origin master

2、问题2

$ git remote add origin git@codehub.devcloud.cn-north-4.huaweicloud.com:hzcz-zsjjd2018jjava2b-6b00001/Git-SMM_hzc.git
fatal: remote origin already exists.

解决:

 1、先输入 $ git remote rm origin

 2、再输入 $ git remote add origin git@***.***.com:testtransfer/Repo1.git    ——(origin 后面为仓库地址) 就不会报错了!
 3、最后再 $ git push origin master (参考上面第4点)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值