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

git提交本地项目到github

2015-12-25 17:28 393 查看

git学习笔记(windows平台)

安装git 在需要将项目提交到git的根目录下打开git bush 1 git init 初始化一个git仓库 //将本地文件添加master,先add一个文件 2 git add 一个文件 或者 git add . 提交当前目录中所有的文件 3 git commit -m "" //链接远程仓库 4 git remote add "远程仓库的地址别名默认是origin" git@git.oschina.net:fuxiaohui/git项目名 在需要将项目提交到git的根目录下打开git bush 5 git remote -v 如果出现以下错误 一,To https://git.oschina.net/fuxiaohui/itone-core.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://git.oschina.net/fuxiaohui/itone-core.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. ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://git.oschina.net/fuxiaohui/itone-core.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. 查看本地分支命令 git branch 查看远程分支命令 git branch -a 执行 git branch --set-upstream-to=origin/远程分支的名字 本地分支的名字 二,如果push出现错误说明本地仓库与远程仓库不一致,得吧远程仓库的值fetch到本地来 7 git fetch 8 git merge 9 $ git fetch 10 $ git merge 这2句命令等价于 $ git pull 可是,这时候又出现了如下的问题: 1上面出现的 [branch "master"]是需要明确(.git/config)如下的内容 [branch "master"] remote = origin merge = refs/heads/master 这等于告诉git2件事: 1,当你处于master branch, 默认的remote就是origin。 2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是 origin)来merge在master branch上所有的改变 如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行: $ git config branch.master.remote origin $ git config branch.master.merge refs/heads/master 之后再重新git pull下。最后git push你的代码吧。


6 git push -u "远程仓库地址别名" master


判断公钥是否添加成功 ssh -T git@git.oschina.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: