- 注册
- https://github.com/
- 其中会创建一个repository(存储仓库)
- ps :名字投你所好
- Windows管理
- https://desktop.github.com/
- 下载客户端
- Linux(CentOS 6.6)管理
使用ssh连接Github
- 执行以下命令行
- 安装git,ssh(一般linux都自带) :yum install git、yum install ssh;
- ssh-keygen -t rsa -C "注册时用的邮箱帐号",执行时会提示输入,全选择回车即可(缺省 或者 说是默认)获得ssh连接密钥,然后可以得到~/.ssh/id_rsa.pub文件,复制其内容;
- https://github.com/Rofound/SaveBase/settings/keys,点击该网页下的add deploy key,title 填写终端系统名称(推荐),下一行则是上行复制的内容;有单选按钮可点,提交;
- 测试连接: ssh -T [email protected] :有success字样信息则证明成功
- 配置Git的配置文件,username和email
- git config --global user.name "your name" //配置用户名
- git config --global user.email "your email" //配置email
- 以下是转载http://blog.chinaunix.net/uid-17188120-id-4650534.html
2 利用Git从本地上传到GitHub
进入所要上传文件的目录输入命令 “git init”
创建一个本地仓库team,使用命令 “git remote add team [email protected]:yourName/yourRepo.git”
youname是你的GitHub的用户名,yourRepo是你要上传到GitHub的仓库,这是你再GitHub上添加的仓库。
比如你要添加一个文件xxx到本地仓库,使用命令 “git add xxx”,可以使用“git add .”自动判断添加哪些文件
添加提交到本地的仓库,使用命令 ”git commit -m ”说明这次的提交“ “
最后把本地仓库team提交到远程的GitHub仓库,使用命令 ”git push origin master“
3 从GitHub克隆项目到本地
到GitHub的某个仓库,然后复制右边的有个“HTTPS clone url”
回到要存放的目录下,使用命令 "git clone https://github.com/chenguolin/scrapy.git",红色的url只是一个例子
如果本地的版本不是最新的,可以使用命令 “git fetch origin”,origin是本地仓库
把更新的内容合并到本地分支,可以使用命令 “git merge origin/master”
如果你不想手动去合并,那么你可以使用: git pull <本地仓库> master // 这个命令可以拉去最新版本并自动合并
4 GitHub的分支管理
创建
1 创建一个本地分支: git branch <新分支名字>
2 将本地分支同步到GitHub上面: git push <本地仓库名> <新分支名>
3 切换到新建立的分支: git checkout <新分支名>
4 为你的分支加入一个新的远程端: git remote add <远程端名字> <地址>
5 查看当前仓库有几个分支: git branch
删除
1 从本地删除一个分支: git branch -d <分支名称>
2 同步到GitHub上面删除这个分支: git push <本地仓库名>
5 常见错误
1 如果出现报错为ERROR: Repository not found.fatal: The remote end hung up unexpectedly则代表你的 origin 的url 链接有误,可能是创建错误,也可能是这个 [email protected]:xxx/new-project.git url 指定不正确。重新创建。