Github初试
###windows下直接安装RailsInstaller之后git就已经被默认安装好了。
###安装RailsInstaller时自动创建的本地git目录C:\Sites\
1、注册github账号并创建仓库。
注册好帐号,比如我的用户名是liweiyitou
创建一个新的仓库(Repository),例如theone
2、将工程文件夹(比如theone)拷贝至C:\Sites\下。
3、执行git命令提交代码至Github。
git init
git add .
git commit -m "first" -a
git remote add origin https://github.com/liweiyitou/theone.git
git push origin master
###在之后git控制台提示中继续再输入github的用户名和密码即可push代码成功哦\(^o^)/~
解释:
在当前目录初始化
添加所有文件
提交,first是提交时的注释
要把网址换为你建立的Repository的网址,github网站上能查到
push到github
=========================================
代码冲突“! [rejected] master -> master (non-fast-forward)”的原因以及解决办法:
①博文选摘之一
如下文章选摘自博文:http://blog.csdn.net/mci2004/article/details/7763399
最近想把自己做的一个小小小小的应用放到github上去,顺便学习下git和玩玩github,我用两台电脑往github上的项目push代码,想模拟social coding的感觉。呵呵,但是出现了这个错误
:
-
To git@github.com:archermind/LEDTorch.apk-for-Android.git
-
! [rejected] master ->
master (non-fast-forward)
-
error: failed to push some refs to 'git@github.com:archermind/LEDTorch.apk-for-Android.git'
-
To prevent you from losing history, non-fast-forward updates were rejected
-
Merge the remote changes before pushing again. See the 'Note about
-
fast-forwards' section of 'git push --help' for details.
错误产生的原因是,因为我在A电脑上向github上的项目push过代码,而又在B电脑上修改了代码并且要push到github上去,这个时候,git为了避免冲突的发生,rejected。
正确的做法是,在push之前git fetch origin,将github上的新代码拉下来,然后在本地merge,如果没有冲突就可以push了,如果有冲突的话要在本地解决冲突后,再push。具体做法就是。
git fetch origin
git merge origin/master
###这两步其实可以简化为git pull origin master
git push origin master
②博文选摘之二
当要push代码到git时,出现提示:
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
-
$ git push origin master
-
To ../remote/
-
! [rejected] master -> master (non-fast forward)
-
error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put,
git cannot make the change on the remote without losing commits, so it
refuses the push. Usually this is caused by another user pushing to the
same branch. You can remedy this by fetching
and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made
locally by using commands like git commit --amend or git rebase. While
you can override the remote by adding --force to the push command, you
should only do so if you are absolutely certain this
is what you want to do. Force-pushes can cause issues for other users
that have fetched the remote branch, and is considered bad practice.
When in doubt, don’t force-push.
问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容
git push -f
2,先把git的东西fetch到你本地然后merge后再push
$ git fetch
$ git merge
这2句命令等价于
可是,这时候又出现了如下的问题:
上面出现的 [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你的代码吧。it works now~
=========================================
- 大小: 15.2 KB
分享到:
相关推荐
表格中的几个网站是github的同步镜像网站,均从网络搜集。下面是镜像网站的优点: 一:速度快,能节省打开github网页的时间和下载程序资源的时间。 二:同步性高,提供几乎和github官网一样的内容。 三:部分网站已...
微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信...
github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程...
GitHub Android App源码
github的详细使用及其相关介绍 包括探索github 加入github 项目托管 工作协同 付费服务等
里面包含github shell、github desktop、github
github的使用方法:本文档简介地介绍了github的使用。
最新的Git与Github巨作课程,课程内容主旨分成了Git&Github极速入门与攻坚实战课程两部分,可以理解为一个是课程的详细教学篇,和一个精华缩减的集合。Git与Github教程详细介绍了Git的工作机制,Git命令行的基础学习...
github插件
GitHub 客户端,实现项目工程代码托管
github漫游指南,详细的介绍github的使用
GitHubDesktop如何转化成中文?
github下载加速插件,Chrome浏览器专用,包括插件伴侣和Github_speed_1_0_8_0.crx
github 使用指南 官方中文
xray macos版,github上太慢了xray macos版,github上太慢了xray macos版,github上太慢了xray macos版,github上太慢了xray macos版,github上太慢了xray macos版,github上太慢了xray macos版,github上太慢了xray...
Github加速 Github下载
Github使用教程.zip 身为程序员,怎么能不会使用github呢
利用广布海内外的大量CDN节点加速Github文件获取速度。
详细介绍如何上传GitHub项目! 1. 先到github 个人网页上建立新的 2. 进入要上传的文件夹内,右键,选择 Git Bash Here 然后,出现如下界面。输入: git clone [刚才建立的新网址] 3. 这个时候,就建立本地 git...
GitHub入门与实践.pdf