1、如何在mac上使用git连接私有的gitlab服务器
首先要 ssh远程登陆工具比等
案 基于SSH直接搭建
Git支持协议主要四种:
本: 需要文件共享系统权限控制
HTTP:速度慢
SSH:同支持读写操作支持匿名读取(Git默认协议)
GIT:快
搭建难易程度特点综合筛选合适ssh并且部服务器基本都ssh服务所省少麻烦基本思路给每ssh帐号家通用户名口令访问显选择做些余并且于repo权限难管理
使用Github候利用rsa.pub公钥/私钥式服务端拥用户公钥(*.pub)跨繁琐口令直接认证提交服务端根据同用户身份其权限着更加灵管理我采用种式
服务端
使远程库访问更加直观先服务器创建名git账户clone候面格式:
git clone git@server:some.git
创建新用户创建repo等目录
$sudo adser git
$su git
$cd ~
$mkdir repos
HOME.ssh目录没则创建创建authorized_keys文件文件用管理所git用户公钥面用户于项目着R+W权限
客户端
于每客户端我需要密钥公钥Github用户.ssh目录定id_rsa.pubid_rsa两文件其第系统公钥另自要保存密钥没终端执行:ssh-keygen完自公钥提交给管理员注册行
完
步管理员团队员公钥添加authorized_keys比同susie加入:
$ cat susie.pub >> authorized_keys
至家通git@server:repos/some.git访问公共版本库
问题
安全问题员登录git用户shell,细节权限支等控制
管理麻烦新建repo,或者增加员比较麻烦尤其修改候
案二 使用Gitolite服务
Gitolite 基于SSH协议构建便管理git repo应用通其源码安装.
安装
安装按照官给定文档轻易实现:
$ git clone git://github.com/sitaramc/gitolite
$ mkdir -p $HOME/bin
$ gitolite/install -to $HOME/bin
$ gitolite setup -pk YourName.pub
执行条命令候gitolite识别则通面两种式解决:
gitolite添加PATH面
通$HOME/bin/gitolite setup -pk YourName.pub 执行
至gitolite服务端搭建完毕发现HOME目录增加文件projects.list目录repositories,者我版本仓库每新建repo候其创建
使用
候说gitolite管理模式创建gitolite-adminrepo管理员通像repo提交配置文件实现git服务器控制
首先repo导入我workspace:前需要配置本ssh,gitolite要求管理员本密钥其注册公钥名字致比我安装候指定 -pk面 admin.pub 则管理员本需要由admin应私钥我通~/.ssh/config进行配置(注:些系统用confMac OSX 效能用config).
host gitolite
user git
hostname yourhostname.com
port 22
identityfile ~/.ssh/admin
我访问gitolite候自根据配置文件执行配置完根据面命令gitolite-admin转移本
git clone gitolite:gitolite-admin.git
克隆完发现gitolite-admin面两目录其conf保存配置文件我通编辑面gitolite.conf文件管理git服务器keydir目录保存用户公钥pub文件
我讲修改repo 提交候gitolite自应用些配置管理程便
配置规则
打gitolite.conf文件看其示例:
To add new users alice, bob, and carol, obtain their public keys and add them to 'keydir' as alice.pub, bob.pub, and carol.pub respectively.
To add a new repo 'foo' and give different levels of access to these users, edit the file 'conf/gitolite.conf' and add lines like this:
repo foo
RW+ = alice
RW = bob
R = carol
面配置文件新建repo foo并且添加三位项目员每权限同提交push管理便效
视化
我能需要web界面管理些项目我目前知道三种式:
git源码自带组件cgi脚本实现使用gitolite服务
gitlab源框架基于ROR新版本再使用gitolite服务
FB源PHP框架 phabricator功能高端档
2、windows git服务器怎么连接
小鸟云服务器niaoyun实例创建好之后,您可以使用以下任意一种方式登录服务器:
远程桌面连接(,MSTSC):采用这种方式登录,请确保实例能访问公网。如果在创建实例时没有购买带宽,则不能使用远程桌面连接。
管理终端VNC:无论您在创建实例时是否购买了带宽,只要您本地有网页浏览器,都可以通过管理控制台的管理终端登录实例。
使用远程桌面连接(MSTSC)登录实例
打开开始菜单>远程桌面连接,或在开始菜单>搜索中输入mstsc。也可以使用快捷键Win+R来启动运行窗口,输入mstsc后回车启动远程桌面连接。
在远程桌面连接对话框中,输入实例的公网IP地址。单击显示选项。
输入用户名,如小鸟云默认为niaoyun。单击允许我保存凭据,然后单击连接。这样以后登录就不需要手动输入密码了。
3、如何将代码上传到git服务器上
1、本地公钥的获取,
cd ~/.ssh
ls
使用指令ssh-keygen,生产公钥,第一个提示时输入文件(默认是id_rsa),第二个提示时输入的是密钥,
公钥放置在id_rsa.pub文件中。
2、按照code的提示,进行代码上传。
2.1 建立一个git文件件,比如git_csdn ,
2.2 git init,建仓操作,
2.3 可以新建一个readme.md, touch README.md
2.4 git add.添加所有文件,git add file,添加file,比如git add README
2.5 git commit -m "first commit"
2.6 git remote add origin git @ url 地址
2.7 git push -u origin master
3、git clone 地址
4、git remote 不带参数,列出已经存在的远程分支
$ git remote
origin
5、配置:
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
出现的问题:Updates were rejected because the tip of your current branch is behind
有如下几种解决方法:
1.使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2.push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
3.若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
分支管理:
1、创建分支: git branch new_branch
2、查看分支:git branch
3、删除分支:git branch -d new_branch
4、切换分支:git checkout new_branch
5、创建分支并切换分支: git checkout -b new_branch即可在本地新建分支,并使用该分支track远程分支
6、提交并推送分支:
git add .
git commit -m "xxx"
git push -u origin new_branch
7、删除远程分支:git push origin --delete new_branch
8、合并分支: git merge new_branch
9、将本地更新上传到远程分支上:
例如本地新建或是更新了内容newfile.c文件,
首先git add newfile.c,
然后git commit -m "add new file",
紧接着git push 本地分支名 远程分支名即可将本地分支更新到远程分支。
10.获取远程分支
git fetch 从远程获取其他用户push上来的新分支
git remote -v 即可查看远程所有的版本信息
4、怎么从外网访问内网git服务器
外网访问内网的服务一般有 以下几种方式:
将 内网服务器置于DMZ区,这样内网和外网都能访问
在DMZ区放置一公共服务器,通过反向代理的方式访问
使用VPN接入内网直接访问
5、本地git软件怎么连接linux服务器地址
1、前期准备
服务器上配置好的git
git客户端
1.1
在服务器上安装git (本机所使用的linux是ubuntu)
在服务器输入命令:sudo apt-get install git即可 然后创建名字为git的用户组和用户
1.2
下载客户端 在浏览器地址栏输入:https://git-for-windows.github.io/
回车后
点击Download进行下载
2、具体操作
2.1
在合适的位置创建一个目录充当git远程仓库(本机位置为/usr/testgit),然后使用init命令初始化仓库
在命令终端输入:
sudo git init –bare
2.2
将git init生成的目录所属者改为git
输入命令:sudo chown -R git:git *
至此服务器端的操作完成。
在客户端合适位置使用git 客户端从服务器资源
2.3
首先打开git客户端
点击Git Bash Here 后出现
在git客户端命名终端输入:
git clone git@xxxxxx:/rrrrr 其中xxxxxx是远程服务器的地址 rrrrr为git仓库所在位置
如果配置正确你选中的目录下会出现名字为testgit的文件夹 testgit文件夹下随意创建若干个文件
2.3
在git客户端上使用命令 git add 111.txt 222.txt 333.txt 或者使用git add .(将本文件夹下所有文件都add) 该命令的作用是告诉git把文件添加到git仓库
2.4
然后使用git commit命令将文件提交到git仓库
-m 后面的内容为本次提交文件的一些注释内容
此时文件还没有从本地仓库上传到远程服务器仓库
2.5
使用push命令将本地仓库中的内容提交到远程仓库
在git客户端命令终端输入:git push origin master
至此本地仓库中的文件上传已经上传到远程服务器仓库。
在其他文件夹下再次使用 git clone 命令 从远程服务器同步仓库
6、怎样将本地仓库和git服务器关联
注意:安装的前提条件是配置好Git的相关环境或者安装好git.exe,此处不再重点提及
上传的步骤:(本文采用 命令界面进行操作)
( git config --global user.email "[email protected]"
git config --global user.name "Your Name")实现登陆
1.进入本地的项目目录,右键“Git Bash here”,调出git命令行界面,然后输入
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
git init
2.就是将目录下的所有文件上传,也可以将“.”换成具体的文件名
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
git add .
3.将项目提交到gitHub
[html] view plain copy 在CODE上查看代码片派生到我的代码片
git commit -m "注释语句"
4.在github上创建新的repository
5.点击 “Create repository”跳转到一个连接,如下红色圈获取到本项目的github地址
6.将本地的代码关联到github上
[html] view plain copy 在CODE上查看代码片派生到我的代码片
git remote add origin 项目的github地址
7.上传代码到github之前需要先pull
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
git pull origin master
8.上传代码到远程仓库
[plain] view plain copy 在CODE上查看代码片派生到我的代码片
git push -u origin master
之后输入账号,密码,上传到github
7、git 连接着一个服务器地址,现在想连接另一个git服务器,如何操作?
gti remote add 服务器别称 url,使用的时候用服务器别名获取。区别服务器的是别名。比如origin就代表是一个,自定义的
8、如何 连接 linux git服务器
1、前期准备服务器上配置好的gitgit客户端1.1 在服务器上安装git (本机所使用的linux是ubuntu) 在服务器输入命令:sudo apt-get install git即可 然后创建名字为git的用户组和用户1.2 下载客户端 在浏览器地址栏输入:https://git-for-windows.github.io/ 回车后 点击Download进行下载2、具体操作2.1 在合适的位置创建一个目录充当git远程仓库(本机位置为/usr/testgit),然后使用init命令初始化仓库 在命令终端输入: sudo git init –bare 2.2 将git init生成的目录所属者改为git 输入命令:sudo chown -R git:git * 至此服务器端的操作完成。 在客户端合适位置使用git 客户端从服务器资源 2.3 首先打开git客户端 点击Git Bash Here 后出现 在git客户端命名终端输入: git clone git@xxxxxx:/rrrrr 其中xxxxxx是远程服务器的地址 rrrrr为git仓库所在位置 如果配置正确你选中的目录下会出现名字为testgit的文件夹 testgit文件夹下随意创建若干个文件 2.3 在git客户端上使用命令 git add 111.txt 222.txt 333.txt 或者使用git add .(将本文件夹下所有文件都add) 该命令的作用是告诉git把文件添加到git仓库2.4 然后使用git commit命令将文件提交到git仓库 -m 后面的内容为本次提交文件的一些注释内容 此时文件还没有从本地仓库上传到远程服务器仓库2.5 使用push命令将本地仓库中的内容提交到远程仓库 在git客户端命令终端输入:git push origin master 至此本地仓库中的文件上传已经上传到远程服务器仓库。 在其他文件夹下再次使用 git clone 命令 从远程服务器同步仓库
9、如何将git服务器提供给其他人使用
1. 架设Git服务器
我们以Ubuntu为例。首先,在git服务器上创建一个名为 'git' 的用户,并为其创建一个.ssh 目录。并将其权限设置为仅git用户有读写权限
$ sudo adser git
$ su git
$ cd
$ mkdir .ssh
$ chmod 700 .ssh
接下来,把开发者的 SSH 公钥添加到这个用户的 authorized_keys 文件中。假设你通过电邮收到了几个公钥并存到了临时文件里。重复一下,公钥大致看起来是这个样子:
$ cat /tmp/id_rsa.john.pub
ssh-rsa /ww+ouN4gSLKssMxXnBOvf9LGt4L
ojG6rs6hPB09j9R/T17//5zytK6Ztg3RPKK+4k
Ez
/nLF6JLtPofwFBlgc+myiv
Pq
dAv8JggJICUvax2T9va5 gsg-keypair
只要把它们逐个追加到 authorized_keys 文件尾部即可,同时将authorized_keys设置为仅git用户有读写权限。
$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat /tmp/id_rsa.jessica.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
现在可以用 --bare 选项运行 git init 来建立一个裸仓库,这会初始化一个不包含工作目录的仓库。
$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init
这时,Join,Josie 或者 Jessica 就可以把它加为远程仓库,推送一个分支,从而把第一个版本的项目文件上传到仓库里了。值得注意的是,每次添加一个新项目都需要通过 shell 登入主机并创建一个裸仓库目录。我们不妨以 gitserver 作为 git 用户及项目仓库所在的主机名。如果在网络内部运行该主机,并在 DNS 中设定 gitserver 指向该主机,那么以下这些命令都是可用的:
# 在 John 的电脑上
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@gitserver:/opt/git/project.git
$ git push origin master
这样,其他人的克隆和推送也一样变得很简单:
$ git clone git@gitserver:/opt/git/project.git
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master
用这个方法可以很快捷地为少数几个开发者架设一个可读写的 Git 服务。
作为一个额外的防范措施,你可以用 Git 自带的 git-shell 工具限制 git 用户的活动范围。只要把它设为 git 用户登入的 shell,那么该用户就无法使用普通的 bash 或者 csh 什么的 shell 程序。编辑/etc/passwd 文件:
$ sudo vim /etc/passwd
在文件末尾,你应该能找到类似这样的行:
git:x:1000:1000::/home/git:/bin/sh
把 bin/sh 改为 /usr/bin/git-shell (或者用 which git-shell 查看它的实际安装路径)。该行修改后的样子如下:
git:x:1000:1000::/home/git:/usr/bin/git-shell
现在 git 用户只能用 SSH 连接来推送和获取 Git 仓库,而不能直接使用主机 shell。尝试普通 SSH 登录的话,会看到下面这样的拒绝信息:
$ ssh git@gitserver
fatal: What do you think I am? A shell?
Connection to gitserver closed.
这里提供的方法,组内所有成员对project都有读写权限,也就是说每个分支都可以push代码,如果需要更加细致的权限控制,请使用Gitosis或者Gitolite。
2. 搭建Gitweb
安装gitweb之后就可以通过网站访问我们的项目了。就像http://git.kernel.org一样显示了
首先需要安装Gitweb,如果没有安装apache,那么直接安装Gitweb,也会将apache2安装的。
$ sudo apt-get install gitweb apache2
安装完成之后,我们只需要修改一下配置文件,将/etc/gitweb.conf文件中的$projectroot修改为放工程文件的目录。
$ vim /etc/gitweb.conf
# path to git projects (<project>.git)
$projectroot = "/opt/git";
至此gitweb就可以使用了,现在可以通过http://[git_server_IP]/gitweb访问了。
3. Push之后发送邮件通知
当组内成员push代码到服务器上之后,会自动发送邮件通知组内所有人员,该次push的具体内容是什么。具体配置方法:
一般在安装Git的时候发送邮件的脚本/usr/share/git-core/contrib/hooks/post-receive-email已经存在了,首先要修改所有者和执行权限,并且安装sendmail。
$ sudo chown git:git post-receive-email
$ sudo chmod 755 post-receive-email
$ sudo apt-get install sendmail
然后到切换到工程目录下的hooks中,添加 post-receive软链接指向 /usr/share/git-core/contrib/hooks/ post-receive-email。
$ cd /opt/git/project.git/hooks
$ ln -s /usr/share/git-core/contrib/hooks/post-receive-email post-receive
最后修改工程目录中的config文件即可。mailinglist是邮件列表, envelopesender是发件人的邮箱,
$ vim /opt/git/project.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = true
[hooks]
mailinglist = "[email protected], [email protected]" # 收件人列表
envelopesender = [email protected] # 送件人地址
emailprefix = "[Project commit] " # 邮件标题前缀
showrev = "git show -C %s; echo" # 不只显示有变化的文件,同时也显示改变的内容
为了使邮件显示的更清楚,还要修改一下工程目录当中的description文件,在description文件中,默认第一行是项目名称,所以要在第一行填入该项目的名称,这个在邮件中会有显示。
$ vim /opt/git/project.git/description
Project_A
10、阿里云服务器 怎么用git部署代码
使用阿里云Ubuntu 12.0.4 64位操作系统做git服务器。
首先git服务器有两种访问方式可以选择:http方式和ssh的方式,http方式更容易使用。
1、http方式的git服务器搭建以及使用git命令行访问:
On the Server
1) Install Ubuntu Server, this is the base of our git server obviously
2) Now we need to install a couple of packages, these being ‘git-core’ and ‘apache2′, we do this like so:-
apt-get update
apt-get install apache2 git-core
3) Now we need to create a new folder for your new repository and set some inital permissons, we do this like so:-
cd /var/www
mkdir test-repo.git
cd test-repo.git
git --bare init
git update-server-info
chown -R www-data.www-data .
4) We now need to enable WebDAV on Apache2 of which we will use to serve the repository:-
a2enmod dav_fs
5) We now need to configure the access restrictions to our repository by creating the following file:-
/etc/apache2/conf.d/git.conf
Then fill it in with the following content:-
<Location /test-repo.git>
DAV on
AuthType Basic
AuthName "Git"
AuthUserFile /etc/apache2/passwd.git
Require valid-user
</Location>
Then save and close the file, lets move on to the next bit..
6) Next we need to create a user account of which you will need to use to browse of commit to the repository..
htpasswd -c /etc/apache2/passwd.git <user>
You could then be prompted to enter the password for the user too and confirm it!
7) Ok that’s it for the server side configuration… we just need to restart Apache2 like so and then we should be ready to move on to the client side stuff!
/etc/init.d/apache2 restart
…you can now move on to the client side stuff!
On the client side
Ok so now we need to create a local (on your desktop machine) repository and then we’ll initiate the new remote repository… So, if your using Linux/MacOSX bring up the terminal and type the following commands:-
mkdir ~/Desktop/test-project
cd ~/Desktop/test-project
git init
git remote add origin http://<user>@<server name or IP address>/test-project.git
touch README
git add .
git commit -a -m “Initial import”
git push origin master
Done! – Your intiial file named ‘README’ which currently is just blank has now been committed and you’ve pushed your code to your new git server which has now completed the Git reposity creation process, now in future you can ‘clone’ your resposity like so:-
git clone <user>@<server name or IP address>/test-project.git
注意上面连接http://<user>@<server name or IP address>/test-project.git中的user就是你htpasswd -c /etc/apache2/passwd.git <user>输入的用户名。
另外新建仓库的时候,只需执行:
cd /var/www
mkdir 项目名
cd 项目名
git --bare init
git update-server-info
chown -R www-data.www-data .
然后在/etc/apache2/conf.d/git.conf中对应添加上面类似段即可。
其中:
AuthUserFile 密码文件名
后面的文件就是你指定的密码文件,你可以
htpasswd -c 密码文件名 <user>
对应指定该项目的用户名和密码即可。添加用户是不要-c参数:
htpasswd 密码文件名 <user>