導航:首頁 > IDC知識 > git連接伺服器

git連接伺服器

發布時間:2020-12-19 09:58:22

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>

與git連接伺服器相關的知識