通过idea工具将本地代码添加到网络git服务器上

来源:互联网 发布:罗技鼠标怎么编程 编辑:程序博客网 时间:2024/06/15 05:35
一,工具

idea、git 安装、配置均不赘述。

二, 本地项目git提交
1.创建本地仓库


2.代码提交到本地git(先add 后commit)


三,项目提交
 window下cmd到项目所在目录。如:
D:\gitspaces\demo\aaa
需要提交到网络git中(如:开源中国):https://git.oschina.net/xxxxx/aaa.git
注:用https的方式
连接,别用SSH的方式连接!

输入git命令:
1.git remote add origin https://git.oschina.net/xxxxx/aaa.git
2.git push origin master 
输入用户名和密码。

如果出现

error: failed to push some refs to 'https://git.oschina.net/xxxxx/aaa.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.

出现错误的主要原因是github中的README.md文件不在本地代码目录中 

 输入git命令:
git pull --rebase origin master

操作步骤:
D:\gitspaces\demo\aaa>git remote add origin https://git.oschina.net/xxxxx/aaa.git

D:\gitspaces\demo\aaa>git push origin master
Username for 'https://git.oschina.net': xxxxx
Password for 'https://xxxxx@git.oschina.net':
To https://git.oschina.net/xxxxx/aaa.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://git.oschina.net/xxxxx/aaa.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.

D:\gitspaces\demo\aaa>git pull --rebase origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.oschina.net/xxxxx/aaa
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 新增aaa目录

Warning: Your console font probably doesn't support Unicode. If you experience s
trange characters in the output, consider switching to a TrueType font such as C
onsolas!

D:\gitspaces\demo\aaa>git push -u origin master
Username for 'https://git.oschina.net': xxxxx
Password for 'https://xxxxx@git.oschina.net':
Counting objects: 50, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (41/41), done.
Writing objects: 100% (50/50), 10.93 KiB | 0 bytes/s, done.
Total 50 (delta 17), reused 0 (delta 0)
To https://git.oschina.net/xxxxx/aaa.git
   825d126..0ff4c7b  master -> master
Branch master set up to track remote branch master from origin.

D:\gitspaces\demo\aaa>


备注:
方法/步骤
在使用git 对源代码进行push到网络git上时可能会出错,信息如下
此时很多人会尝试下面的命令把当前分支代码上传到master分支上。
$ git push -u origin master
但依然没能解决问题
出现错误的主要原因是网络git中的README.md文件不在本地代码目录中
可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin master
执行上面代码后可以看到本地代码库中多了README.md文件


原创粉丝点击