Ubuntu上GitLab项目创建完整流程
在创建项目前,需先完成GitLab的安装与基础配置。以下是基于Ubuntu 20.04/22.04的包管理器安装步骤(推荐新手使用):
sudo apt update && sudo apt upgrade -y,确保系统软件包为最新版本,避免安装冲突。sudo apt install -y curl openssh-server ca-certificates postfix,安装GitLab运行所需的依赖(openssh-server用于SSH连接,postfix用于邮件通知)。curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash命令,将GitLab的官方软件源添加到系统中(gitlab-ce为社区版,若需企业版可将gitlab-ce替换为gitlab-ee)。sudo apt install gitlab-ce,系统会自动下载并安装GitLab。sudo gitlab-ctl reconfigure应用默认配置,再通过sudo gitlab-ctl start启动GitLab服务。首次安装后,可通过sudo vim /etc/gitlab/initial_root_password查看root用户的初始密码(有效期24小时)。http://<服务器IP>或http://gitlab.example.com,需替换为实际域名/IP)。Admin Area → Users → root → Edit)。my-web-app),建议使用英文或拼音。README.md文件(用于项目说明),方便后续克隆后快速查看项目信息。项目创建后,需将本地代码推送到GitLab远程仓库。以下是详细步骤:
git clone <项目克隆地址>(克隆地址可在项目页面的Clone按钮旁获取,支持HTTPS或SSH方式)。例如:git clone https://gitlab.example.com/your-username/my-web-app.git
cd my-web-app
git add .(.表示添加所有文件)。git commit -m "Initial commit"。master分支的提交推送到GitLab的origin远程仓库,执行git push -u origin master(首次推送需使用-u参数关联远程分支)。git branch <分支名>创建新分支(如feature/login),用git checkout <分支名>切换分支,开发完成后通过git merge合并到主分支。.gitlab-ci.yml文件,定义自动化测试、构建或部署流程(如自动运行单元测试、部署到服务器)。通过以上步骤,即可在Ubuntu上完成GitLab项目的创建与基础配置。后续可根据项目需求,进一步探索GitLab的高级功能(如Issue跟踪、Wiki文档、容器注册等)。