Gitlab和Github一样的步骤,这里以Github演示
一般流程
Command line instructions
- Git global setup
git config --global user.name "Don"
git config --global user.email "xxxx@gmail.com"
- Create a new repository
git clone https://gitlab.com/Dongshen/Today.git
cd Today
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
- Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/Dongshen/Today.git
git add .
git commit -m "Initial commit"
git push -u origin master
- Existing Git repository
cd existing_repo
git remote add origin https://gitlab.com/Dongshen/Today.git
git push -u origin --all
git push -u origin --tags
创建过程
- 首先在Github上创建New repository

其中重要的一点是选择创建
.gitignore
,这个github创建的文件是全面的,比自己写要完善的多。(当然从别的地方拷贝也是可行的)
- 本地创建git
创建一个文件夹,使用git init创建一个空的git库
mkdir JianShu //创建文件夹
cd JianShu
git init //创建空的git库
- 关联到远程仓库
git remote add origin https://github.com/mistdon/Jianshu
这里推荐使用https, - 拉取远程文件到本地
git pull origin master --allow-unrelated-histories
拉取成功后,自动生成一个commit,保存即可(wq + Enter) - 推送到远程
git push origin master
OK,成功的话就可以在主页上看到。
常见错误
- 在第4步,如果不添加
--allow-unrelated-histories
会出现fatal: unrelated_histories
的错误; - ssh, git@而不是https,如果github的设置不正确的话,会出现
fatal: Could not read from remote repository.
的错误
网友评论