ubuntu git 上传到 bitbucket 已存在工程

来源:互联网 发布:java怎么与mysql连接 编辑:程序博客网 时间:2024/06/05 04:24

bitbucket相比github可以免费的创建私有代码仓库,现在我有一个c语言工程代码,需要上传到bitbucket方便后期维护和保存。
首先登陆bitbucket注册一个账号,后创建一个仓库, 格式如下:
创建私有仓库

上图中,用户名和所有者根据自己的要求设置。

现在回到ubuntu环境下,现在有一个工程文件如下所示:

hello@hello-machine:~/work/other/tmp$ ls -a.  ..  main.c  Makefile  test.c  test.h

首先执行git init 创建初始版本库

hello@hello-machine:~/work/other/tmp$ git init初始化空的 Git 版本库于 /home/hello/work/other/tmp/.git/hello@hello-machine:~/work/other/tmp$ ls -a.  ..  .git  main.c  Makefile  test.c  test.h

好了,现在就可以吧目前存在的文件添加到仓库了,由于我们拥有多个文件,因此要执行:

git add .

add后面的“.”是将所有文件添加到仓库,之后就可以提交了:

hello@hello-machine:~/work/other/tmp$ git commit -m "this just a test"        [master (根提交) 7bc4303] this just a test 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Makefile create mode 100644 main.c create mode 100644 test.c create mode 100644 test.h

接下来就来连接远程仓库,以https的形式连接:

$ git remote add origin  https://bigPillow@bitbucket.org/bigPillow/test.git

其中的后面的地址,可以在创建仓库的时候看到,比如:
这里写图片描述

连接完毕之后,就可以上传代码到远程仓库了:

git push -u origin master

第一次提交需要加上-u参数,这样Git不仅仅把本地的master分支内容推送的远程新的master分支,而且将本地的master分支和远程的master分支关联起来,方面以后推送,假如修改文件后需要再次推送的话,就可以吧-u参数去掉,直接git push origin master就可以了。

1 0