顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

2018年4月9日 星期一

[Git] gitlab 遇到 internal API unreachable remote rejected 问题


  • 修改 /etc/gitlab/gitlab.rb
    # gitlab_shell['http_settings'] = { user: 'username', password: 'password', ca_file: '/etc/ssl/cert.pem', ca_path: '/etc/pki/tls/certs', self_signed_cert: false}

    修改如下:

    gitlab_shell['http_settings'] = {self_signed_cert: true}
  • reconfigure & restart
    #gitlab-ctl reconfigure ; gitlab-ctl restart


Reference :
[1] GitLab: Failed to authorize your Git request: inte

2018年3月1日 星期四

[Git] commit empty folder

Git 設計是不提供上傳空資料夾,故要上傳空資料夾就必須加入一個檔案至資料夾中。方法如下:

  • 在所有空資料夾中加入 .gitkeep
    find . -type d -empty -exec touch {}/.gitkeep \;
  • 根目錄下建立 .gitignore,加入
    !.gitkeep
    !.gitignore

Reference:
[1] git提交空文件夹目录结构新

2017年10月28日 星期六

[Git] Rename a local and remote branch

#git checkout <old_branch>
#git branch -m <new_branch>
#git push origin :<old_branch>
#git push origin <new_branch>:refs/heads/<new_branch>

2017年3月27日 星期一

[Git] Import Existing Local Git Master Repo into Gitlab: Git user Access Issues


  • Clone old repository
    #git clone http://gitlab.example.com/old_repository.git
  • Mirror to new repository
    #cd old_repository
    #git push --mirror http://gitlab.example.com/new-repository.git
Reference :
[1] import-an-existing-git-project-into-gitlab

2016年4月29日 星期五

[Git] Git Server 整合 LDAP on Ubuntu 14.04

因為手殘不小心把dav_passwd檔案給砍掉,就決定把git的帳號認證改整合到LDAP上。

不多說,開始吧!
  • 開啟Apache LDAP Module
  • a2enmod ldap
    a2enmod authnz_ldap

  • 直接找CN - 新增 git.conf 
  • #vim /etc/apache2/sites-available/git.conf
            DocumentRoot /home/git
            ServerName git.jesse.com
            ErrorLog /var/log/apache2/git-error.log
            CustomLog /var/log/apache2/git-access.log combined
            SetEnv GIT_PROJECT_ROOT /home/git
            SetEnv GIT_HTTP_EXPORT_ALL
            ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

            <Directory "/usr/lib/git-core">
                            Options +ExecCGI
                            Allow From All
            </Directory>

            <Directory "/home/git">
                            Dav on
                            Order allow,deny
                            Allow from all
            </Directory>

            <Location "/${project}.git">
                    AuthName "GIT Repo"
                    AuthType Basic
                    AuthBasicProvider ldap
                    AuthLDAPURL "ldap://${LDAP_IP}:389/${BASE_DN}?uid?sub?(objectClass=*)"
                    Require valid-user

            </Location>

  • 使用group的方式 - 新增 git.conf 
  • #vim /etc/apache2/sites-available/git.conf
    Note :
    * BASE_DN : 指的是要搜尋的根目錄
    * uid:指的是要搜尋的attribute
    * sub:指的是要搜尋所有的sub tree
    * ldap-group : 設定的objecClass是groupOfNames,在Member的attribute加入所有的user cn
    。 * group的概念有點像是使用者帳號密碼先做驗證,驗證成功後,再確認該使用者是不是在設定的Group裡面,是的話回傳True,不是則False。
            DocumentRoot /home/git
            ServerName git.jesse.com
            ErrorLog /var/log/apache2/git-error.log
            CustomLog /var/log/apache2/git-access.log combined
            SetEnv GIT_PROJECT_ROOT /home/git
            SetEnv GIT_HTTP_EXPORT_ALL
            ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

            <Directory "/usr/lib/git-core">
                            Options +ExecCGI
                            Allow From All
            </Directory>

            <Directory "/home/git">
                            Dav on
                            Order allow,deny
                            Allow from all
            </Directory>

            <Location "/${project}.git">
                    AuthType Basic
                    AuthName "Git Access"
                    AuthBasicProvider ldap
                    AuthLDAPBindDN "cn=admin,dc=jesse,dc=com,dc=tw"
                    AuthLDAPBindPassword "password"
                    AuthLDAPGroupAttribute member
                    AuthLDAPURL "ldap://${LDAP_IP}:389/${BASE_DN}?uid?sub?(objectClass=*)"
                    Require ldap-group cn=$group_name,dc=jesse,dc=com,dc=tw

    </Location>

  • enable git.conf
  • #ln -s /etc/apache2/sites-available/git.conf /etc/apache2/sites-enabled/git.conf

  • 重新啟動Server
  • #/etc/init.d/apache2 restart

2015年8月18日 星期二

[Git] 使用HTTP存取Git Server on Ubuntu 14.04


  • 安裝 Git和apache2
  • #apt-get install git-core apache2 apache2-utils

  • 啟動DAV模組
  • #a2enmod dav_fs
    #a2enmod dav

  • 新增git.conf
  • #vim /etc/apache2/sites-available/git.conf
    <VirtualHost 192.168.1.50>
            DocumentRoot /home/git
            ErrorLog /var/log/apache2/git-error.log
            CustomLog /var/log/apache2/git-access.log combined

            <Location "/test.git">
                    DAV on
                    AuthType Basic
                    AuthName "Git Access"
                    AuthUserFile /etc/apache2/dav_git.passwd
                    Require valid-user
            </Location>
    </VirtualHost>

  • 建立帳號密碼
  • #htpasswd -c /etc/apache2/dav_git.passwd USERNAME

  • enable git.conf
  • #ln -s /etc/apache2/sites-available/git.conf /etc/apache2/sites-enabled/git.conf

  • 重新啟動Server
  • #/etc/init.d/apache2 restart

  • 建立Repository
  • #mkdir /home/git/test.git
    #cd /home/git/test.git
    #git init --bare
    #git update-server-info
    #cp hooks/post-update.sample hooks/post-update
    #chown www-data:www-data /home/git/test.git -R

  • 測試git repository
  • #git clone http://192.168.1.50/test.git
    #cd test
    #touch README
    #git add README
    #git commit -m "init"
    #git push

  • 如果發生Push Error,則可使用10解決
  • error: Cannot access URL http://192.168.1.50/test.git/, return code 22
    fatal: git-http-push failed
    error: failed to push some refs to 'http://192.168.1.50/test.git'

  • 解決Push Error
  • 發生錯誤的原因為未認證,可修正clinet端的config解決該問題。
    #vim test/.git/config
    Modify
    [remote "origin"]
            url = http://192.168.1.50/test.git

    to
    [remote "origin"]
            url = http://jesse@192.168.1.50/test.git


Reference:
[1] Debian Linux 架設使用 HTTP 存取 的 Git Server

2014年8月11日 星期一

[Git] git init vs git init --bare (git did not exit cleanly (exit code 1))

圖一 : 比對 git
Create repository,可以加入 --bare 參數,若不加入--bare參數,git相關檔案將會被建立在 .git 資料夾,相反的,加入--bare參數,則會直接在當下目錄下建立git相關檔案。而比對兩種方式所建立的檔案,只有在 config 設定檔參數是不一樣(圖一)。

測試這兩種模式,發現這兩種模式最大的差異,是bare repository可以使用 git push,而一般repository的模式下,若執行git push將會發生下面的錯誤訊息。這也說明,多人一起開發的模式(須使用git push),就要使用 bare Repository的模式。

git did not exit cleanly (exit code 1)

Note :
如果原本是一般模式要轉成--bare模式,只要修改 config檔(圖一),並將.git下的所有檔案,副至到期望的資料夾底下即可。


2014年7月3日 星期四

[Git] No refs in common and none specified; doing nothing.

Push error on github
#git push 
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date

Solution :
#git push origin master

Reference : [1] Git Tip: git push ‘No refs in common and none specified’

2014年4月17日 星期四

[Git] error: The requested URL returned error: 403 while accessing

Push error on github
#git push
error: The requested URL returned error: 403 while accessing https: ...

Solution : 
#vim .git/config
modify
[remote "origin"]
        url="https://github.com/linuxxunil..."
to
[remote "origin"]
        url="https://linuxxunil@github.com/linuxxunil..."


Reference :
[1] http://blog.csdn.net/happyteafriends/article/details/11554043

2013年11月28日 星期四

[Git] CVS、RCS、VCS、SCM 名詞定義

在看Git的時候,發現VCS/RCS/CVS/SCM這些名詞,由於這些名詞都很像,現在很多人也都混這使用,所以就查了一下,並重新整理這幾個名詞的定義。

圖一(圖片來源)
  • VCS(Version Control System) : 版本控制系統
    常常我們所講的Git、SVN。。。等等版本控制系統,還可在細分以下幾個部分,
    • Revision Control : 有時候也稱之RCS(Revision Control System),而RCS主要一個唯一的數字或文字,用來記錄版本與版本的相對關係,像SVN是用數子來做為表示,而Git則使用一串SHA的數子來表示。
    • Source Control:而Source Control主要是記錄著檔案與檔案之間的差異,而再搭配RCS系統,即可以清楚的了解版本與版本之間的差異。
    • Source Code Management:再更進階一點,利用SCM來做更加複雜且實用的功能,將每個版本之間的關係透過一個叫repository的東西統一管理、並且可以提供像是branch、tag、merged等等複雜功能的管理機制。
    • Source Configuration Management:而有些人指的SCM是比上面所說的Source Code Management再更進階的更能(Source Code Management只是個子集合),這部分加上了建置管理、部屬管理、整合管理、相依性管理、釋出管理等功能 。
  • CVS (Concurrent Version Control System) : 由於這個名詞容易跟VCS搞混(太像了),其實CVS是一套實現Version Control System得一套軟體,就像是SVN、Git一樣。

Reference:
[1] Source control vs. Revision Control?
[2] Wiki - Software_configuration_management
[3] Wiki - Revision_control
[4] Git - Document