上传项目:
1.我们使用git需要先安装git工具,这里给出下载地址:
https://git-for-windows.github.io/
打开Git Bash
首先配置自己的身份,这样在提交代码的时候就能知道是谁提交的
输入git config --global user.name "名字"
git config --global user.email "邮箱地址"
2.进入Github首页,点击New repository新建一个项目
3.填写相应信息后点击create即可
Repository name: 仓库名称
Description(可选): 仓库描述介绍
Public, Private : 仓库权限(公开共享,私有或指定合作者)
Initialize this repository with a README: 添加一个README.md
gitignore: 不需要进行版本管理的仓库类型,对应生成文件.gitignore
license: 证书类型,对应生成文件LICENSE
(来自:https://www.cnblogs.com/cxk1995/p/5800196.html)
4.接下来就到本地操作了,cd 到本地文件夹下
5.使用$ git clone https://github/xx账号/xx项目.git克隆到本地
6.编辑项目
7. $ git add .(将改动添加到暂存区)
8. $ git commit –m”提交说明” 如“first commit”
9. git remote add origin https://github/xx账号/xx项目.git
10. git push -u origin master (注:此操作目的是把本地仓库push到github上面,此步骤需要你输入帐号和密码)
错误解决:
1. unable to auto-detect email address
解决:找到工程目录 (Project) 的.git文件夹,打开之后找到config文件,在最后边加上:
[user]
email=your email
name=your name
(来自:https://blog.csdn.net/howard789/article/details/78526659)
2.src refspec master does not match any
解决:原因分析:
引起该错误的原因是目录中没有文件,空目录是不能提交上去的
解决办法:
$ touch README
$ git add README
$ git commit –m’first commit’
$ git push origin master
(来自:https://blog.csdn.net/s164828378/article/details/52425208)
3. failed to push some refs to git
出现错误的主要原因是github中的README.md文件不在本地代码目录中,
可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin master
4.git 添加远程github仓库的时候提示错误:fatal: remote origin already exists.
1、先删除远程 Git 仓库
$ git remote rm origin
2、再添加远程 Git 仓库
$ git remote add origin git@github.com:FBing/java-code-generator
5. github访问及上传慢的问题
在本地host文件中添加映射,步骤如下:
用文本编辑器打开hosts文件,位于C:\Windows\System32\drivers\etc目录下
打开 http://tool.chinaz.com/dns ,这是一个查询域名映射关系的工具
查询 github.global.ssl.fastly.net 和 assets-cdn.github.com 两个地址
多查几次,选择一个稳定,延迟较低的 ip 按如下方式添加到host文件