Git简单使用

Git简单使用

GitHub上传项目

使用工具git
git安装

1 windows ---> https://git-scm.com/downloads 
2 linux ----> yum -y install git | apt-get install git 

window使用git命令:

1 1.进入git的安装文件夹,双击git-cmd.exe,即可进入使用git命令
2 2.将git命令添加至环境变量path里,打开cmd进入命令提示符直接使用

指定github的用户名和邮箱:

1 git --global user.name cq146637
2 git --global user.email xxxxxxx@qq.com

创建一个新的仓库

# 首先进入仓库所在目录,然后执行如下步骤:

# 1.准备README.md文件,必须有(如果github仓库没有初始化)
echo "# python_practice" >> README.md

# 2.初始化本地仓库(新建本地仓库)
git init

# 3.将本地文件添加到本地仓库中
git add ./*

# 4.提交commit文件,填写本次提交的描述,虽然无卵用但必须提交
git commit -m "first commit"

# 5.指定远程仓库地址,你github仓库的地址,这个仓库将存放本地仓库中的所有文件(origin只是别名,你可以随便取)
git remote add origin https://github.com/cq146637/python_practice.git

# 6.将本地仓库推送至github仓库(origin设为默认远程仓库)
git push -u origin master

# 7.如果git没有登录需要填写用户名&密码
Username for 'https://github.com': cq146637
Password for 'https://cq146637@github.com':

# 至此本地仓库已经上传成功,可以在自己的github仓库查看相应项目

迭代更新自己github仓库

# 首先进入一个空目录,为了克隆原仓库内容准备,然后执行如下步骤:

# 1.克隆需要更新的github仓库
git clone https://github.com/cq146637/python_practice.git

# 2.进入项目文件夹
cd project_name

# 3.初始化本地仓库
git init

# 4.修改项目文件,添加新文件
...

# 5.将更新完成的项目添加至本地仓库
git add ./*

# 6.提交commit文件,填写本次提交的描述,虽然无卵用但必须提交
git commit -m "project update"

# 7.指定远程仓库地址,你github仓库的地址,这个仓库将存放本地仓库中的所有文件(origin只是别名,你可以随便取)
git remote add origin https://github.com/cq146637/python_practice.git

# 8.将本地仓库推送至github仓库(origin设为默认远程仓库)
git push -u origin master

# 9.如果git没有登录需要填写用户名&密码
Username for 'https://github.com': cq146637
Password for 'https://cq146637@github.com':