git 服务器架设

2024-04-15 01:18
文章标签 服务器 git 架设

本文主要是介绍git 服务器架设,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

建立一个 Git 代码共享仓库服务器。

1. 服务器

通常用 SSH 协议即可,我们应该为 Git 创建一个专用账号。

$ sudo useradd git$ sudo passwd git
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


创建一个用来保存代码仓库的目录,注意赋予 git 账号读写权限。

$ sudo mkdir -p /var/git.server/project1
$ cd /var/git.server$ sudo chown git project1
$ sudo chgrp git project1$ ls -l
total 4
drwxr-xr-x 2 git git 4096 2010-05-17 00:55 project1


初始化 project1,注意在服务器上我们无需保留工作目录,因此创建一个纯粹(bare)的代码仓库。

$ cd project1/$ sudo su git$ pwd
/var/git.server/project1$ git --bare init
Initialized empty Git repository in /var/git.server/project1/$ ls -l
total 32
drwxr-xr-x 2 git git 4096 2010-05-17 00:59 branches
-rw-r--r-- 1 git git   66 2010-05-17 00:59 config
-rw-r--r-- 1 git git   73 2010-05-17 00:59 description
-rw-r--r-- 1 git git   23 2010-05-17 00:59 HEAD
drwxr-xr-x 2 git git 4096 2010-05-17 00:59 hooks
drwxr-xr-x 2 git git 4096 2010-05-17 00:59 info
drwxr-xr-x 4 git git 4096 2010-05-17 00:59 objects
drwxr-xr-x 4 git git 4096 2010-05-17 00:59 refs$ exit


我们在服务器上克隆一份用于管理和测试(应该禁止直接操作服务器仓库目录)。

$ git clone /var/git.server/project1/
Initialized empty Git repository in /home/yuhen/project1/.git/
warning: You appear to have cloned an empty repository.$ ls -al project1
total 12
drwxr-xr-x  3 yuhen yuhen 4096 2010-05-17 01:02 .
drwxr-xr-x 10 yuhen yuhen 4096 2010-05-17 01:02 ..
drwxr-xr-x  7 yuhen yuhen 4096 2010-05-17 01:02 .git


我们添加点项目初始化文件。

$ cd project1$ cat > .gitingore << end
> *~
> *.swp
> end$ touch README$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitingore
#       README
nothing added to commit but untracked files present (use "git add" to track)$ git add .
$ git commit -am "Start"
[master (root-commit) 723471e] Start1 files changed, 2 insertions(+), 0 deletions(-)create mode 100644 .gitingorecreate mode 100644 README


我们向服务器提交第一个版本。

$ git push git@localhost:/var/git.server/project1/ masterCounting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 258 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@localhost:/var/git.server/project1/* [new branch]      master -> master


通常情况下,我们可以用 origin 来代替服务器地址,不过当前测试账号没有写 git.server/project1 的权限,因此用 ssh 路径。同时需要指定 branch。

2. 客户端

好了,现在作为一个普通程序员,我们开始为 project1 项目工作。

$ git clone git@192.168.1.202:/var/git.server/project1
Initialized empty Git repository in /home/yuhen/project1/.git/
git@192.168.1.202's password: 
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.$ ls -al project1
total 16
drwxr-xr-x  3 yuhen yuhen 4096 2010-05-17 01:11 .
drwxr-xr-x 27 yuhen yuhen 4096 2010-05-17 01:10 ..
drwxr-xr-x  8 yuhen yuhen 4096 2010-05-17 01:11 .git
-rw-r--r--  1 yuhen yuhen    9 2010-05-17 01:11 .gitingore
-rw-r--r--  1 yuhen yuhen    0 2010-05-17 01:11 README


代码已经克隆回来了,我们添加或修改一些文件。

$ touch INSTALL$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    INSTALL
nothing added to commit but untracked files present (use "git add" to track)$ git add .$ git commit -am "INSTALL"
[master b85e275] INSTALLCommitter: yuhen <yuhen@yuhen-desktop.(none)>0 files changed, 0 insertions(+), 0 deletions(-)create mode 100644 INSTALL


在将代码提交(push)到服务器之前,首先要确认相关更新已经合并(merge)到 master 了,还应该先从服务器刷新(pull)最新代码,以确保自己的提交不会和别人最新提交的代码冲突。

$ git pull origin master
git@192.168.1.202's password: 
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From 192.168.1.202:/var/git.server/project1* branch            master     -> FETCH_HEAD
Merge made by recursive.0 files changed, 0 insertions(+), 0 deletions(-)create mode 100644 HISTORY$ git push origin master
git@192.168.1.202's password: 
Could not chdir to home directory /home/git: No such file or directory
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 474 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
To git@192.168.1.202:/var/git.server/project1c4d7b1e..ee8cfb3  master -> master$ git log
commit ee8cfb3d14eed091e6f96d60af68ec07c05ab09d
Merge: b85e275 c4d7b1e
Author: yuhen <yuhen@yuhen-desktop.(none)>
Date:   Mon May 17 01:17:49 2010 +0800Merge branch 'master' of 192.168.1.202:/var/git.server/project1commit c4d7b1e796cf52e0b600f2c7e992f304052fa8c1
Author: Q.yuhen <qyuhen@hotmail.com>
Date:   Mon May 17 01:17:26 2010 +0800HISTORYcommit b85e275b52812e3d9ac36da78fb8cc924380a58c
Author: yuhen <yuhen@yuhen-desktop.(none)>
Date:   Mon May 17 01:13:35 2010 +0800INSTALLcommit 723471e3421d7fdfa80bf31e5c27f5a174e95afd
Author: Q.yuhen <qyuhen@hotmail.com>
Date:   Mon May 17 01:05:53 2010 +0800Start


我们应该避免频繁向服务器提交代码,而是在一个相对稳定的版本测试通过后再进行。
基本操作就是这些了,当然我们还可以提供只读账号或者 HTTP 访问协议,相关内容可参考《Pro Git》。


这篇关于git 服务器架设的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/904538

相关文章

2024.6.24 IDEA中文乱码问题(服务器 控制台 TOMcat)实测已解决

1.问题产生原因: 1.文件编码不一致:如果文件的编码方式与IDEA设置的编码方式不一致,就会产生乱码。确保文件和IDEA使用相同的编码,通常是UTF-8。2.IDEA设置问题:检查IDEA的全局编码设置和项目编码设置是否正确。3.终端或控制台编码问题:如果你在终端或控制台看到乱码,可能是终端的编码设置问题。确保终端使用的是支持你的文件的编码方式。 2.解决方案: 1.File -> S

通过SSH隧道实现通过远程服务器上外网

搭建隧道 autossh -M 0 -f -D 1080 -C -N user1@remotehost##验证隧道是否生效,查看1080端口是否启动netstat -tuln | grep 1080## 测试ssh 隧道是否生效curl -x socks5h://127.0.0.1:1080 -I http://www.github.com 将autossh 设置为服务,隧道开机启动

【服务器运维】MySQL数据存储至数据盘

查看磁盘及分区 [root@MySQL tmp]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical)

【服务器运维】CentOS6 minimal 离线安装MySQL5.7

1.准备安装包(版本因人而异,所以下面的命令中版本省略,实际操作中用Tab自动补全就好了) cloog-ppl-0.15.7-1.2.el6.x86_64.rpmcpp-4.4.7-23.el6.x86_64.rpmgcc-4.4.7-23.el6.x86_64.rpmgcc-c++-4.4.7-23.el6.x86_64.rpmglibc-2.12-1.212.el6.x86_64.r

【服务器运维】CentOS7 minimal 离线安装 gcc perl vmware-tools

0. 本机在有网的情况下,下载CentOS镜像 https://www.centos.org/download/ 1. 取出rpm 有的情况可能不需要net-tools,但是如果出现跟ifconfig相关的错误,就把它安装上。另外如果不想升级内核版本的话,就找对应内核版本的rpm版本安装 perl-Time-Local-1.2300-2.el7.noarch.rpmperl-Tim

SQL Server中,always on服务器的相关操作

在SQL Server中,建立了always on服务,可用于数据库的同步备份,当数据库出现问题后,always on服务会自动切换主从服务器。 例如192.168.1.10为主服务器,12为从服务器,当主服务器出现问题后,always on自动将主服务器切换为12,保证数据库正常访问。 对于always on服务器有如下操作: 1、切换主从服务器:假如需要手动切换主从服务器时(如果两个服务

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

在服务器上浏览图片

@StarSky 2018-10-26 15:09 字数 15971 阅读 28 https://www.zybuluo.com/StarSky/note/1294871 来源 2018-09-27 线上服务器安装 imgcat Tool   2018-09-27 线上服务器安装 imgcat 0. 准备文件:iterm2_shell_integration.bash1. 在有权限

服务器雪崩的应对策略之----SQL优化

SQL语句的优化是数据库性能优化的重要方面,特别是在处理大规模数据或高频访问时。作为一个C++程序员,理解SQL优化不仅有助于编写高效的数据库操作代码,还能增强对系统性能瓶颈的整体把握。以下是详细的SQL语句优化技巧和策略: SQL优化 1. 选择合适的数据类型2. 使用索引3. 优化查询4. 范式化和反范式化5. 查询重写6. 使用缓存7. 优化数据库设计8. 分析和监控9. 调整配置1、

青龙面板部署通用教程,含服务器、路由器、X86等部署方法

1. 拉取镜像/更新镜像 docker pull whyour/qinglong:latest 2. 删除镜像 docker rmi whyour/qinglong:latest 3. 启动容器 普通服务器 docker run -dit \-v $PWD/ql/config:/ql/config \-v $PWD/ql/log:/ql/log \-v $PWD/ql/db: