博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to Run Your Own Git Server
阅读量:7173 次
发布时间:2019-06-29

本文共 3844 字,大约阅读时间需要 12 分钟。

参考:

Install Git on your server

In this tutorial we are considering a use-case where we have a remote server and a local server and we will work between these machines. For the sake of simplicity we will call them remote-server and local-server.

First, install Git on both machines. You can install Git from the packages already available via the repos or your distros, or you can do it manually. In this article we will use the simpler method:

sudo apt-get install git-core

Then add a user for Git.

sudo useradd git

passwd git
In order to ease access to the server let's set-up a password-less ssh login. First create ssh keys on your local machine:

ssh-keygen -t rsa

It will ask you to provide the location for storing the key, just hit Enter to use the default location. The second question will be to provide it with a pass phrase which will be needed to access the remote server. It generates two keys - a public key and a private key. Note down the location of the public key which you will need in the next step.

Now you have to copy these keys to the server so that the two machines can talk to each other. Run the following command on your local machine:

cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Now ssh into the server and create a project directory for Git.客户端用git用户名登录所以服务端也用git用户登录避免权限问题  You can use the desired path for the repo.

git@server:~ $ mkdir -p /home/swapnil/project-1.git

Then change to this directory:

cd /home/swapnil/project-1.git

Then create an empty repo:服务器上的repository

git init --bare

Initialized empty Git repository in /home/swapnil/project-1.git
We now need to create a Git repo on the local machine.

mkdir -p /home/swapnil/git/project

And change to this directory:

cd /home/swapnil/git/project

Now create the files that you need for the project in this directory. Stay in this directory and initiate git:

git init

Initialized empty Git repository in /home/swapnil/git/project
Now add files to the repo:

git add .

Now every time you add a file or make changes you have to run the add command above. You also need to write a commit message with every change in a file. The commit message basically tells what changes were made.

git commit -m "message" -a

[master (root-commit) 57331ee] message
2 files changed, 2 insertions(+)
create mode 100644 GoT.txt
create mode 100644 writing.txt
In this case I had a file called GoT (Game of Thrones review) and I made some changes, so when I ran the command it specified that changes were made to the file. In the above command '-a' option means commits for all files in the repo. If you made changes to only one you can specify the name of that file instead of using '-a'.

An example:

git commit -m "message" GoT.txt

[master e517b10] message
1 file changed, 1 insertion(+)
Until now we have been working on the local server. Now we have to push these changes to the server so the work is accessible over the Internet and you can collaborate with other team members.

git remote add origin ssh://git@remote-server/git-respo-path-on-server

Now you can push or pull changes between the server and local machine using the 'push' or 'pull' option:

git push origin master

If there are other team members who want to work with the project they need to clone the repo on the server to their local machine:

git clone ssh://git@remote-server:/home/swapnil/project.git 

Here /home/swapnil/project.git is the project path on the remote server, exchange the values for your own server.

Then change directory on the local machine (exchange project with the name of project on your server):

cd /project

Now they can edit files, write commit change messages and then push them to the server:

git commit -m 'corrections in GoT.txt story' -a

And then push changes:
git push origin master

转载于:https://www.cnblogs.com/qike/p/5461633.html

你可能感兴趣的文章
vSphere 5.5 vCenter迁移至分布式交换机
查看>>
排序 遍历
查看>>
第二次作业
查看>>
Mysql主从复制
查看>>
高斯消元法解非奇异线性方程组的MATLAB程序
查看>>
CSS3 3d环境实现立体 魔方效果代码
查看>>
全面总结sizeof的用法(定义、语法、指针变量、数组、结构体、类、联合体、位域位段)...
查看>>
python2升级到python3
查看>>
做好该做的把未来交给明天
查看>>
脚本里添加crontab的方法
查看>>
configure:error: Package requirements (libffi >= 3.0.0) were not met
查看>>
java 抽象类与接口的区别
查看>>
Linux驱动模块编译模板
查看>>
我的友情链接
查看>>
MySQL 5.6.12 安装
查看>>
MCSA&MCP认证证书
查看>>
我的友情链接
查看>>
进阶篇第五期:UIScrollView的那点事儿
查看>>
CSS系列:CSS中盒子模型
查看>>
2017网络安全产业研究报告学习笔记
查看>>