如何在git创建仓库并上传更新

版权声明:未经本人许可,不得用于商业用途及传统媒体。转载请注明出处! https://blog.csdn.net/qikaihuting/article/details/77856033

Git global setup

git config --global user.name "your_define_name"
git config --global user.email "your_email_name"

全局配置:创建一个用户名以及所关联的邮箱地址

Create a new repository

git clone (your address,for example)https://github.com/liuqk_spirits/classification.git
cd classification
touch README.MD
git add README.MD
git commit -m "add README"
git push-u origin master

 通常我们会在gitlab或者github上先创建一个项目,并且完善项目的一些设置,如项目描述,是否公开等,也会简单地创建一个readme.md;

然后再clone到本地,并且自动关联本地文件夹(命名与远程仓库名相同),对应第一行,再执行第二行,更新上传操作都是在这个文件夹下进行;

在这里创建了一个名为classification的仓库库,创建了readme文件,并上传到github对应的classification repository中。

git add * #添加*表示所有,可以指定具体的文件名或者文件夹;

git commit -m "your_explain" #提交添加文件的注释;

git push -u origin master # 推送到远程仓库,第一次上传要使用 -u 这个参数

注意:关联远程目标仓库之后,会在本地生成一个隐藏文件.git,里面是关联的相关信息。

Existing folder or Git repository

cd existing_folder #in your home address
git init
git remote add origin http://github.com/liuqk_spirits/your_repository_name.git
git add *
git commit -m "***"
git push -u origin master

第三行是将已创建的本地文件夹关联到远程仓库,本地文件夹名要和仓库名一致;

若git push -u origin master出错,则在push之前先pull,执行git pull --rebase origin master,最后再push便OK

Delete files in the repository

cd your_repository
git rm ** #files you want delete or use 'git rm -r your folder'
git commit -m "delete files"
git push origin master

 可以使用git status查看当前操作的状态,将会提示你下一步该怎么做,git remote rm origin http://your repository address.git用于删除一个仓库。

以上操作基本可以满足git常用操作。


 

猜你喜欢

转载自blog.csdn.net/qikaihuting/article/details/77856033