使用github提交代码

windows下上传代码到github

1.  创建Github账户

2. 新建仓库


填写项目名称,建议勾选Initialize this repository with a README


3. 打开Git Bash,输入以下命令生成密钥验证身份

ssh-keygen -C 'your@email.address' -t rsa

之后会提示输入密码指令

Enter passphrase (empty for no passphrase):
输入密码,然后确认密码,出现以下提示说明成功生成了密钥

Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

默认生成的.ssh文件夹应该在C盘下

然后在github上,找到Account settings


在左侧菜单找到ssh选项


在右侧点击Add SSH key,Title可以随便输入,打开C盘.ssh文件夹,找到id_rsa.pub文件,把里面的内容复制出来,输入Key,点击Add key按钮,就行了

在GIt Bash下输入命令测试刚才输入的公钥是否正确

ssh -T git@github.com
出现warning

The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

输入yes,回车,出现

Hi username! You've successfully authenticated, but GitHub does not
# provide shell access
表示添加SSH Key成功

详见 https://help.github.com/articles/generating-ssh-keys

4. 初始设置

git config --global user.name "Your Real Name"
git config --global user.email you@email.address

5. 克隆git上的仓库到本地

输入命令

git clone https://github.com/cc1218/TestSlideMenu.git

这里的git地址可以在 找到

默认克隆路径是C盘下的Documents,建议改变路径,有两种方法,一是在Git Bash下cd到指定文件夹,二是在指定文件夹右键选择Git Bash

6. 提交代码

输入指令

git init
如果提交一个文件可以用

git add README.md


如果提交文件夹下的所有文件

git add .


git commit -m 'first commit' first commit是注释


commit时,如果之前没有设置用户名密码,这时候会提示输入用户名密码


git remote add origin https://github.com/cc1218/TestSlideMenu.git

git push origin master

这样就上传成功了



可能出现的错误解决办法:

1. 如果执行

git remote add origin https://github.com/cc1218/TestSlideMenu.git
的时候出现fatal: remote origin already exists

可以执行

git remote rm origin

再执行

git remote add origin 

2. 如果执行git push origin master的时候出现error:failed to push som refs to.......
可以先执行

git pull origin master git@github.com:cc1218/TestSlideMenu.git

或者 

git clone https://github.com/cc1218/TestSlideMenu.git
把服务器上的github文件拉下来,再push上去


一些问题及经验:

http://www.cppblog.com/deercoder/archive/2011/11/13/160050.html

http://www.cnblogs.com/visi/archive/2011/09/07/2169938.html


//--------------------------------------

删除文件或文件夹

跳转到项目所在文件夹目录,然后执行

git rm -r one-of-the-directories
git commit -m "Remove duplicated directory"
git push origin master

取消已经暂存的文件

接下来的两个小节将演示如何取消暂存区域中的文件,以及如何取消工作目录中已修改的文件。不用担心,查看文件状态的时候就提示了该如何撤消,所以不需要死记硬背。来看下面的例子,有两个修改过的文件,我们想要分开提交,但不小心用 git add . 全加到了暂存区域。该如何撤消暂存其中的一个文件呢?其实,git status 的命令输出已经告诉了我们该怎么做:

$ git add .
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.txt
        modified:   benchmarks.rb

就在 “Changes to be committed” 下面,括号中有提示,可以使用 git reset HEAD <file>... 的方式取消暂存。好吧,我们来试试取消暂存 benchmarks.rb 文件:

$ git reset HEAD benchmarks.rb
Unstaged changes after reset:
M       benchmarks.rb
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   README.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   benchmarks.rb

这条命令看起来有些古怪,先别管,能用就行。现在 benchmarks.rb 文件又回到了之前已修改未暂存的状态。

http://git-scm.com/book/zh/Git-%E5%9F%BA%E7%A1%80-%E6%92%A4%E6%B6%88%E6%93%8D%E4%BD%9C


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值