您的位置:首页 > 编程语言

如何使用git命令同步代码到github或提交到多个远程仓库

2015-12-07 12:14 1881 查看

如何提交到远程仓库

1.首先在github上注册一个帐号,然后新建一个库。

2.本地

mkdir wty

cd wty

git init

git config –list //设置user.email/username等

编写代码文件后:

git add .

git commit -m “说明标签”

查看远程仓库

git remote -v

添加远程仓库

git remote add [shortname] https://github.com/" target=_blank>

git remote add origin [url=https://github.com/]https://github.com/
用户名/库.git

//”origin“这个相当于是个别名,你可以自己随便写,也可以写成当前文件夹的名,后面的地址是你在GITHUB刚刚新建的 库 地址, 你建了哪几个库,你到GITHUB找到你建的库,点进去就能看到相应的地址。

推送数据到远程仓库

git push [remote-name] [branch-name]

git push -u origin master

推送数据到远程仓库中可能会出现的错误:

git push -u origin master //会提示输入用户名和密码

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

error: 无法推送一些引用到 ‘[url=https://github.com/Lvzwq/zwq.git]https://github.com/Lvzwq/zwq.git’

提示:更新被拒绝,因为远程版本库包含您本地尚不存在的提交。这通常是因为另外

提示:一个版本库已推送了相同的引用。再次推送前,您可能需要先合并远程变更

提示:(如 ‘git pull’)。

提示:详见 ‘git push –help’ 中的 ‘Note about fast-forwards’ 小节。

输入完之后会出现以上错误。

然后输入:

git fetch

git merge //会出现错误:

fatal:未指定提交并且merge.defaultToUpstream 未设置。

此时需要重新git add,git commit

然后执行:

4000
git push -u origin master //会出现以下错误:

! [rejected] master -> master (non-fast-forward)

error: 无法推送一些引用到 ‘https://github.com/xxxxx/xxx.git

提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。

提示:再次推送前,先与远程变更合并(如 ‘git pull’)。详见

提示:’git push –help’ 中的 ‘Note about fast-forwards’ 小节。

执行(不必要):

git config branch.master.remote origin

git config branch.master.merge refs/heads/master

与远程合并:

git pull

git add .

git commit -m “second push”

如何提交到多个远程仓库

1.

git remote add oschina https://git.oschina.net/free/Mapper.git

git remote add github https://github.com/abel533/Mapper.git

git push oschina master

git push github master

2.

git remote add all https://git.oschina.net/free/Mapper.git

git remote set-url –add all https://github.com/abel533/Mapper.git

如果有多个,按照上面这一个命令进行添加。

git push all
--
all

等同于直接编辑.git/config文件

[remote “all”]

url = https://github.com/abel533/Mapper.git

url = https://git.oschina.net/free/Mapper.git
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: