新建项目上传到git步骤

 原文地址(超详细):http://blog.youkuaiyun.com/zamamiro/article/details/70172900

 

  1、使用cd命令切换到项目目录,通过git init把它变成Git仓库,再通过git add .把项目添加到仓库;

 

  2、再通过git commit -m "注释内容"把项目提交到仓库"

 

  3、在Github上设置好SSH密钥后,新建一个远程仓库,通过git remote add origin https://github.com/guyibang/TEST2.git将本地仓库和远程仓库进行关联(这里为你的git项目的地址);

 

  4、最后通过git push -u origin master把本地仓库的项目推送到远程仓库(也就是Github)上;

由于新建的远程仓库是空的,所以要加上-u这个参数

 

  5、此时执行第5点命令可能会报如下错误:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/shut-up/redisDemo.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.

那是因为远程仓库与本地仓库不一致,导致错误,此时需要先git pull使远程仓库与本地仓库合并

 

  7、此时git pull也会出现如下错误,

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

因为本地仓库没有与远程仓库进行关联,需要执行命令git branch --set-upstream-to=origin/master master

 

  8、此时再执行git pull命令,再执行git push -u origin master就可以上传成功了。

如果git pull报错,fatal: refusing to merge unrelated histories,是因为两个根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并。

可通过一下命令强制合并:

git pull origin master --allow-unrelated-histories
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值