新建项目添加到git上步骤

1、在Git网站上创建项目git库


2、本地创建项目文件


3、命令行:切换到本地项目文件夹下

cd MySecondDemo/


4、命令行:初始化git

yuanzhiying:MySecondDemo yuanzhiying$ git init

Initialized empty Git repository in /Users/yuanzhiying/Code/MySecondDemo/.git/


5、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git add .


6、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git commit -m "first commit"


7、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git remote add origin git@git.oschina.net:yuanzhiying/MySecondDemo.git


8、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git push origin master

结果出错:

To git@git.oschina.net:yuanzhiying/MySecondDemo.git

 ! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'git@git.oschina.net:yuanzhiying/MySecondDemo.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.


9、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git pull origin master

结果:

warning: no common commits

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 5 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (5/5), done.

From git.oschina.net:yuanzhiying/MySecondDemo

 * branch            master     -> FETCH_HEAD

 * [new branch]      master     -> origin/master

Merge made by the 'recursive' strategy.

 .gitignore |  20 ++++

 LICENSE    | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 README.md  |   1 +

 3 files changed, 360 insertions(+)

 create mode 100644 .gitignore

 create mode 100644 LICENSE

 create mode 100644 README.md


10、命令行

yuanzhiying:MySecondDemo yuanzhiying$ git push origin master

结果:

Counting objects: 29, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (26/26), done.

Writing objects: 100% (29/29), 13.43 KiB | 0 bytes/s, done.

Total 29 (delta 2), reused 0 (delta 0)

To git@git.oschina.net:yuanzhiying/MySecondDemo.git

   ef139dd..d34ead5  master -> master


11、命令行

yuanzhiying:MySecondDemo yuanzhiying$ 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


12、命令行:

yuanzhiying:MySecondDemo yuanzhiying$ git branch -a

master

  remotes/origin/master


13、命令行

yuanzhiying:MySecondDemo yuanzhiying$ git branch --set-upstream-to=origin/master master

Branch master set up to track remote branch master from origin.

这样在我们每次想push或者pull的时候,只需要 输入git push 或者git pull即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值