工作中一般都用git进行项目管理,自己以前没有保存文件的习惯,发现工作了好几年,保存的文件太少,想把一些文件保存在github上,自己在github上创建了仓库,管理自己的文件,记录一下创建仓库,建立分支的过程。
一. 创建仓库
1、环境:centOS系统,xshell,已安装git,若未安装,直接使用 yum install git
安装即可;安装完git后,使用如下命令,设置自己的name和email;
git config --global user.name "Your Name"
git config --global user.email you@example.com
2、去github上创建自己的Repository,创建页面https://github.com/new,为自己的仓库命名后,直接点击Create repository即可,创建后,进入官方介绍界面,按照步骤操作即可;
官方给出的创建过程如图:
touch README.md
git init
git add README.md
git commit -m “first commit”
git remote add origin https://github.com/zxy987872674/LearnCode.git
git push -u origin master
若没有错误,则你的第一次提交就完成了,但是我在执行这步的时候,有错误:
error: The requested URL returned error: 403 while accessing
https://github.com/zxy987872674/LearnCode.git/info/refs
修改git的配置文件:
被注释掉的是原来的url,修改url即可,再次执行git push -u origin master,即可执行成功。
二. 创建和删除分支:
在本地新建一个分支: git branch newBranch
切换到你的新分支: git checkout newBranch
将新分支发布在github上: git push origin newBranch
在本地删除一个分支: git branch -d newBranch
在github远程端删除一个分支: git push origin :newBranch (分支名前的冒号代表删除)
/git push origin –delete newBranch
注意删除远程分支后,如果有对应的本地分支,本地分支并不会同步删除!