标签:
Git push本地代码到新建远程仓库
来源 http://blog.csdn.net/u011043843/article/details/33336625
1、创建一个新的仓库: 自己传图累死了 借网上图一用
2、在Git bash下创建并初始化本地仓库
3、找到要上传到远程仓库的项目文件,放入到bless目录下面或其子目录下面
.git是git init命令后自动创建的,不用管
4、将远程仓库与本地仓库关联
dwqs/bless.git分别用你们注册的账户名和创建的远程仓库名代替,其他不变。嘿嘿,不然就上传到我的仓库来了
5、将项目添加到本地仓库
该命令之后,项目被添加到暂存区,然后必须利用git的命令提交,
-m 之后的相当于注释部分
6、然后,推送到远程仓库
由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。
(注意 我在此步操作时 出错)
git push -u origin master
To https://git.oschina.net/xxxx/java-test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘https://git.oschina.net/xxxx/java-test.git‘
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.
)
解决方案 git 告诉你 远程有最新的代码 你并没有获取到
首先第一步 1. git fetch origin
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
From https://git.oschina.net/xxxx/java-test
Merge branch ‘master‘ of https://git.oschina.net/xxxx/java-test
* [new branch] master -> origin/master
第二步 2.git pull origin master
From https://git.oschina.net/xxxx/java-test
* branch master -> FETCH_HEAD
Merge made by the ‘recursive‘ strategy.
.gitignore | 6 ++
LICENSE | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
README.md | 1 +
3 files changed, 198 insertions(+)
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 README.md
第三步 在照上面的 git push -u origin master
Counting objects: 4699, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4458/4458), done.
Writing objects: 100% (4699/4699), 39.35 MiB | 1.65 MiB/s, done.
Total 4699 (delta 603), reused 0 (delta 0)
查看结果
从现在起,只要本地作了提交,就可以通过命令:
git push origin master
把本地master分支的最新修改推送至Git,现在,你就拥有了真正的分布式版本库!
Git push本地代码到新建远程仓库
标签:
原文地址:http://www.cnblogs.com/wangdaijun/p/5154466.html