使用Git拉取和推送到仓库
0、前置工作
首先安装和配置git ,参考:
没有仓库的情况
创建仓库然后复制其地址,建立远程链接:
![在这里插入图片描述](https://img-blog.csdnimg.cn/0f5e6e33735a41c283c3dfbea0bfc828.png)
有仓库的情况
直接复制仓库地址,然后使用命令clone 拉取整个仓库:
git clone xxxxx.git
1、git 第一次上传文件到仓库
1、进入要上传文件的目录 (右键 Git Bash here)
执行:
git init
![](https://img-blog.csdnimg.cn/20191123111638993.png)
2、查看仓库当前状态
git status
![](https://img-blog.csdnimg.cn/20191123111815318.png)
3、提交文件到仓库
git add .
git add <file>
![](https://img-blog.csdnimg.cn/20191123112117316.png)
4、保存到仓库
git commit -m "我新建了一个文件"
![](https://img-blog.csdnimg.cn/20191123112205628.png)
5、在查看github上仓库的地址
![](https://img-blog.csdnimg.cn/20191123112411486.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzgyMzQyMw==,size_16,color_FFFFFF,t_70)
6、设置远程仓库地址,建立连接:
git remote add origin xxxx.git
![](https://img-blog.csdnimg.cn/20191123112458889.png)
7、提交代码到仓库
git push -u origin master
![](https://img-blog.csdnimg.cn/20191123112600723.png)
8、查看提交的代码
![](https://img-blog.csdnimg.cn/20191123112712451.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzgyMzQyMw==,size_16,color_FFFFFF,t_70)
2、拉取仓库代码修改并提交
1、拉取代码
git pull
![](https://img-blog.csdnimg.cn/20191123112916911.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzgyMzQyMw==,size_16,color_FFFFFF,t_70)
2、修改代码,查看状态
git status
![](https://img-blog.csdnimg.cn/20191123113022511.png)
3、提交代码
git push
![](https://img-blog.csdnimg.cn/20191123113230211.png)
![](https://img-blog.csdnimg.cn/20191123113142683.png)
总结:
git add . 将项目添加到暂存区git commit -m "注释内容" 将项目提交到本地git仓库git push 将项目提交到远程git仓库
|