Git指南 - Git提交新项目

初次提交

  1. 在要提交的项目处右键,有Git Bash Here,点击后出现类似cmd命令行,也可以在任意处或开始菜单中打开Git Bash Here,然后输入cd c:/XXX/XXX,即要提交的项目路径
  2. 初始化
$ git init
Initialized empty Git repository in E:/myProject/XX/.git/
  1. 连接远程库
$ git remote add c6 git@gitee.com:XXX/XX.git

c6是本地的自定义名称,是git@gitee.com:XXX/XX.git的别名,可自由选择,例如origin
git@gitee.com:XXX/XX.git是远端项目的ssh,以码云为例:
在这里插入图片描述
输入命令后可以用以下命令进行查看

$ git remote -v
c6      git@gitee.com:XXX/XX.git (fetch)
c6      git@gitee.com:XXX/XX.git (push)

若要删除

$ git remote rm c6
  1. 提交(push)
$ git commit -m "c6"

c6是一个备注信息,写本次提交的内容介绍等

$ git add .

将文件夹下的所有内容作为要提交的内容

$ git push c6 master

此处的c6是第三步连接远程库时所取的名字

如果远端项目有文件,会提示错误

$ git push c6 master
To gitee.com:XXX/XX.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:XXX/XX.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.

错误的意思是说

![拒绝]master->master(先取)
错误:未能将一些参考资料推送到“git@gitee.com:XXX/ XXX .git”
提示:更新被拒绝,因为远程包含您所做的工作
提示:没有本地。这通常是由另一个存储库推送引起的
提示:指向相同的ref。您可能想首先集成远程更改
提示:(例如,“git pull…”)然后再推。
提示:详情请参阅“git push -help”中的“关于快进的说明”。

所以需要先更新项目,获取远端的项目内容

$ git pull --rebase c6 master

然后执行提交

$ git push c6 master

至此,远端将有了刚提交的内容

提交到另一个代码托管库

完成以上步骤后,若想将代码提交到Github上

  1. 连接远端,即重复上面的第三步
$ git remote add github git@github.com:XXX/XX.git
  1. 提交代码,即重复上面的第四步
$ git push github master

提交更改

$ git commit -m "提交的内容介绍"
$ git push c6 master
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值