创建版本库
mkdir -p /demo/helloworld-git
cd /demo/helloworld-git
git init
ls -al
将文件提交到本地版本库
cd /demo/helloworld-git
echo "hello world" > helloworld.txt
git add helloworld.txt
git commit -m ‘helloworld-master’
git log
rm helloworld.tx
git checkout helloworld.txt
创建本地分支
git branch
git branch new-branch
git branch -D new-branch
切换本地分支
git branch new-branch
echo “世界你好” > helloworld.txt
git commit -m helloworld-new-branch
git checkout master cat helloworld.txt //显示helloworld
git checkout new-branch cat helloworld.txt //显示 世界你好
在GitHub上创建开源项目
前面介绍的都是操作本地版本库和本地分支,git管理源代码都会使用远程的Git托管服务器(eg:GitHub)
git config --global user.name xuwuhao
git config --global user.email 1060xxxxx7@qq.com
然后输入用户名和密码
git remote add origin https://github.com/xuwuhao/xuwuhao.git
git push -u origin master //master是远程版本库origin中的主分支
git branch -a //查看所有本地和远程分支
git clone https://github.com/xuwuhao/xuwuhao.git //使用如下命令可以下载整个工程
git pull origin master //获得某一分支的最新内容