这篇文章基于开发者操作(而不是负责人),
也就是不包含新建仓库的过程。
1. 注册gitlab账号(略)
2. 添加SSH Keys
-
2.1 先从home目录cd到.ssh下检查:
cd ./.ssh
-
2.2 若没有红框中的文件则执行:
ssh-keygen -t rsa -C "your.email@example.com" -b 4096
,中间使用自己的邮箱 -
2.3 将生成的秘钥复制(使用代码
pbcopy < ~/.ssh/id_rsa.pub
)到gitlab网页端-头像-profile-SSH Keys中
注意空白内的提示即可,然后Title可以随意取一个
更多详细内容可以参考官方Help文档
3. 简单操作
新建项目
(这里是新建项目之后的操作说明)
- Command line instructions
git config --global user.name "pxxxb@xxxxxxx.com"
git config --global user.email "pxxx@xxxxxxxx.com"
- Create a new repository
git clone git@192.168.xxxxxxx:FaceRec/ArcsoftApp.git
cd ArcsoftApp
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 git@192.168.xxxxxxx:FaceRec/ArcsoftApp.git
git add .
git commit -m "Initial commit"
git push -u origin master
- Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin git@192.168.xxxxxxx:FaceRec/ArcsoftApp.git
git push -u origin --all
git push -u origin --tags
更新项目
-
克隆
(cd 到你想建立项目的位置)先克隆服务器上的项目:git clone <URL>
这样项目会保存在你指定的文件夹下面。
-
修改
在本地对项目的代码进行修改或者增加文件的增删 -
暂存区
将修改保存到暂存区git add .
.
代表“所有”,也可使用git add xxx
单独进行 -
本地库
将暂存区的内容提交到git仓库:git commit -a -m "提交添加的注释信息"
-
远程库
将本地库中的最新信息发送:git push
后续
报错
$ git push
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
关于使用梯子导致gitlab报错的解决(暂时挖个坑),可参考用 VPN 上网时如何使用 Git
更多操作
- 查看暂存区状态以及修改:
git status
- 查看历史提交:
git log
- 分支:
git branch
- 版本退回:
get reset
- …
一些理论
- 本地仓库、暂存区、远程仓库
- GitLab项目有三种级别(可见类型):private project、internal project、public project
更多关于Git和Gitlab的内容可以参考:Git & Gitlab 使用指南
参考: