2015-09-17 98 views
2

我有多個域名上的多個項目,我有這樣的文件夾中的每個域項目文件。如何爲多個項目設置git?

domain1 -> web-domain1 
domain2 -> web-domain2 

將每個域推送到版本控制帳戶(github)帳戶和託管帳戶(heroku)。

所有域文件夾都包含在一個單一的文件夾根目錄

root 

我應該安裝git的,這樣我可以把每一個項目,因爲我在它是如何工作的。我需要在每個Web項目上執行git init嗎?

或者是否有可能只有一個git init,以便我只有一個本地git倉庫,但我可以配置它來執行具體操作。

通過細節我的意思是隻推動項目相關的文件到正確的域名/主機提供商。

+1

可能重複http://stackoverflow.com/questions/2732020/git-repository-layout-被comited用於服務器與 - 多項目) –

回答

1

是否需要在每個Web項目上執行git init?

總之,是的。

Git,GitHub和Heroku都適合在任何特定時刻處理單個項目。如果您的項目A,B和C彼此獨立,則每個項目都需要在GitHub上本地存儲庫以及自己的Heroku應用程序。

如果您想將源代碼管理保存在一個大型主存儲庫中,可以設想將您推送到GitHub的單個Git存儲庫設置爲root/,然後將每個應用程序目錄內的獨立Git存儲庫推送到Heroku。這是有效的,因爲Git首先在當前目錄中查找.git/目錄,然後查看目錄的父目錄,因此當您在項目文件夾中時,您將提交到本地應用程序以推送到Heroku,以及何時在root/中,你會提交到GitHub。你會注意到這個方案,但是每次你想提交時,你都需要做兩次:一次用於Heroku,一次用於GitHub。我敢打賭,很快就會變得惱人。

0

你可以使用這個shell腳本來管理多個git倉庫。

你可以運行git clone https://github.com/robbenz/gitme.git來看看。我也會在下面發佈它。

在文本編輯器中打開腳本,然後輸入不同git項目的文件路徑。

我叫gitme運行此腳本我~/.bash_profile保存一個alias,然後你可以同時運行在所有的Git項目的git statusgit pushgit pull。項目可與一個唯一的或通用的提交消息

#!/bin/bash -e 

# enter in your different git projects 
REPOS=( 
/Users/you/repo1 
/Users/you/repo2 
/Users/you/repo3 
/Users/you/repo4 
) 

MOVE="Moving to next REPO... \n" 

tput setaf 2;echo "What do ya wanna do? You can say push, pull, commit, ftp push, or status"; tput sgr0 

read input 

if [ $input = "commit" ] 
then 
    tput setaf 2;echo "Do you want a unique commit message? [y/n]";tput sgr0 
    read ans 
    if [ $ans = "y" ] 
    then 
     for i in "${REPOS[@]}" 
     do 
      cd "$i" 
      tput setaf 6;pwd;tput sgr0 
      git add . -A 
      read -p "Commit description: " desc 
      git commit -m "$desc" 
      tput setaf 2;echo $MOVE;tput sgr0 
      sleep 1 
     done 
    else 
     for i in "${REPOS[@]}" 
     do 
      cd "$i" 
      tput setaf 6;pwd;tput sgr0 
      git add . -A 
      git commit -m "autocommit backup point" 
      tput setaf 2;echo $MOVE;tput sgr0 
      sleep 1 
     done 
    fi 
elif [ $input = "push" ] || [ $input = "pull" ] || [ $input = "ftp push" ] || [ $input = "status" ] 
    then 
     for i in "${REPOS[@]}" 
do 
    cd "$i" 
    tput setaf 6;pwd;tput sgr0 
    git $input 
    tput setaf 2;echo $MOVE;tput sgr0 
    sleep 1 
    done 
else tput setaf 1;echo "Sorry, thats not on the list";tput sgr0 
fi 
[GIT庫佈局用於與多個項目服務器(的