【git】创建一个新的本地仓库并上传代码(整理)

之前写过一篇 http://blog.csdn.net/commshare/article/details/20526369



感觉还是不清晰,所以今天又试验了好几次,总结如下:


1. 首先搭建远程仓库

远端:

 git --bare init 

就ok了!


注意

加入了--bare之后呢,就不要直接在这个git目录下加入新文件,也不要完成push 了。


否则会报错:

fatal: This operation must be run in a work tree


这是因为加入了--bare导致的。



====

git --bare init 

之后呢,就可以在gitweb中看到这个仓库了。


2.  本地代码上传到远端

(1)git init 

(2)git remote add origin  file:///本地仓库路径

(3)加入一个新文件

(4)push origin master就好了。


然后就ok了。

========================================

我的过程如下:

root@Ubuntu32:/home/zhangbin/STM/platinum/myui# ls
chrisHaseman-Chapter-2-aaeaa28
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git init
Initialized empty Git repository in /home/zhangbin/STM/platinum/myui/.git/
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git remote add origin file:///home/zhangbin/alex/gitProject/meUI.git
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git pull origin master
fatal: Couldn't find remote ref master
fatal: The remote end hung up unexpectedly
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# ls
chrisHaseman-Chapter-2-aaeaa28
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# touch README.MD
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git add README.MD 
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git push origin master
error: src refspec master does not match any.
error: failed to push some refs to 'file:///home/zhangbin/alex/gitProject/meUI.git'
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git commit -m "initial commit"
[master (root-commit) 3e5f447] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.MD
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To file:///home/zhangbin/alex/gitProject/meUI.git
 * [new branch]      master -> master
root@Ubuntu32:/home/zhangbin/STM/platinum/myui# 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等风来不如迎风去

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值