yuandan 发表于 2018-1-11 08:51:44

CentOS7上GitLab的使用

生成SSH Keys
  生成root账号的ssh key
  

# ssh-keygen -t rsa -C "admin@example.com"  

https://images2015.cnblogs.com/blog/582266/201604/582266-20160409192338156-1598174476.png
  显示pub key的值
  

# cat ~/.ssh/id_rsa.pub  

https://images2015.cnblogs.com/blog/582266/201604/582266-20160409193205531-1269315389.png
  复制显示出来的 pub key
  以root账号登陆gitlab,点击 "profile settings" 然后点击 "SSH Keys"
https://images2015.cnblogs.com/blog/582266/201604/582266-20160409191946515-1940728531.png
  将复制的pub key粘贴进去,然后点击 Add key
https://images2015.cnblogs.com/blog/582266/201604/582266-20160409193124890-1539462397.png

创建一个GitLab仓库
  点击 +New Project
https://images2015.cnblogs.com/blog/582266/201604/582266-20160409224612672-868671415.png
  填写必要信息,点击 Create Project,这样一个Gitlab仓库就创建好了
https://images2015.cnblogs.com/blog/582266/201604/582266-20160409224729906-1654436835.png

通过命令行来提交项目
  首先,检查git是否已经安装
  

git --version  

  

https://images2015.cnblogs.com/blog/582266/201604/582266-20160409182913234-1718976677.png
  如果没有显示git的版本信息,说明还没有安装git,可以使用如下命令安装git
  

yum install git  

  

  Git全局设置
  

git config --global user.name "Administrator"  
git config --global user.email "admin@example.com"
  

  使用core.editor改变默认编辑器
  

git config --global core.editor vim  

  验证Git全局设置
  

git config --global --list  

  将本地项目提交到GitLab仓库
  

cd /root/php-mysql-development  
touch README.md
  
git init
  
git remote add origin git@gitlab.example.com:root/php-mysql-development.git
  
git add .
  
git commit -a -m "whole project commit"
  
git push -u origin master
  

  


通过命令提交一个文件到新分支
  添加新分支
  

git checkout -b NAME-OF-BRANCH  

  添加要提交的文件
  

git add NAME-OF-YOUR-FILE  

  

  添加提交
  

git commit -m “DESCRIBE COMMIT IN A FEW WORDS”  

  

  提交文件到新分支
  

git push origin NAME-OF-BRANCH  


Git常用命令
  切换到master分支
  

git checkout master  

  

  将GitLab仓库的更新文件同步回本地
  

git pull origin NAME-OF-BRANCH -u  

  

  切换到其他分支
  

git checkout NAME-OF-BRANCH  

  

  检查更改的文件
  

git status  

  

  添加文件提交
  

git add CHANGES IN RED  
git commit -m "DESCRIBE THE INTENTION OF THE COMMIT"
  

  

  将更改提交到GitLab仓库
  

git push origin NAME-OF-BRANCH  

  

  删除Git仓库中的所有变更
  

git clean -f  

  

  将其他分支合并到master分支
  

git checkout NAME-OF-BRANCH  
git merge master
  

  
页: [1]
查看完整版本: CentOS7上GitLab的使用