![](https://img.haomeiwen.com/i1221013/9e709f5075d912d6.png)
Git是什么##
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
配置Git##
-
查看git版本
查看git版本
- 设定用户和邮箱
git config --global user.name "<Your Name>"
git config --global user.email "<youremail@example.com>"
Repository##
1.git init
新建文件夹mkdir hello-world
,进入到hello-world文件夹,使用命令行:
git init
![](https://img.haomeiwen.com/i1221013/983bdfbdf0bb44a5.png)
2.新增(add)和提交(commit)
在hello-world文件夹新建readme.txt
touch readme.txt
,查看repo状态git status
![](https://img.haomeiwen.com/i1221013/a15b3256ae3c2417.png)
用命令
git add
告诉Git,把文件添加到仓库:
git add readme.txt
用命令git commit告诉Git,把文件提交到仓库:
git commit -m "add a readme file"
add and commit
在readme.txt中添加文字后,用git diff
查看自上次commit后之间的变化。
git diff
提交新修改,git commit -m "<your commit message>"
![](https://img.haomeiwen.com/i1221013/dea9d3936f8f8896.png)
github##
上面介绍的只是在本地建立repository,要想分享给别人或者团队合作,我们得把它提交到远程仓库。
1.新建远程仓库
![](https://img.haomeiwen.com/i1221013/83f20d6b0a23b054.png)
2.远程连接(会提示github账号和密码)
![](https://img.haomeiwen.com/i1221013/4a46ee68ab3e9aac.png)
git remote add origin https://github.com/leechpee/hello-world.git
git push -u origin master
![](https://img.haomeiwen.com/i1221013/03018970c4cba86c.png)
我们就能在自己的github上看到如下结果:
![](https://img.haomeiwen.com/i1221013/c9c87f3163464dd7.png)
网友评论