This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tech:devops:git [2017/12/19 23:07] rk4n3 |
tech:devops:git [2019/06/08 13:19] (current) rk4n3 |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Git Topics ====== | ||
- | ==== Installing git-lfs on Ubuntu ==== | + | ====== General Git Topics ====== |
- | * Some basic pre-requisites: <code>apt install software-properties-common</code> | + | |
- | * Set up repository: <code>curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash</code> | + | ==== Basic Config ==== |
- | * Install from repository: <code>apt install git-lfs</code> | + | <code>git config --global user.name 'Your Name' |
- | * Each user will need to do: ''git lfs install'' | + | git config --global user.email 'your@email.com' |
+ | git config --global core.pager 'less -x3r' | ||
+ | git config --global diff.tool 'vimdiff' | ||
+ | git config --global diff.guitool 'gvimdiff' | ||
+ | git config --global difftool.prompt 'false' | ||
+ | git config --global http.sslverify 'false'</code> | ||
==== Some history/view tips ==== | ==== Some history/view tips ==== | ||
+ | * Show files involved in a particular commit: <code>git diff-tree --no-commit-id --name-only -r commitid</code> | ||
* Show basic history for a file:<code>git log --all -- path/to/file.ext</code> | * Show basic history for a file:<code>git log --all -- path/to/file.ext</code> | ||
* Show all pull/push activity:<code>git reflog show --date=iso origin/master</code> | * Show all pull/push activity:<code>git reflog show --date=iso origin/master</code> | ||
Line 30: | Line 35: | ||
\\ | \\ | ||
- | ==== Locking master branch ==== | + | ------ |
+ | ====== GitLab ====== | ||
+ | ==== Import Project into Gitlab ==== | ||
+ | <code> | ||
+ | git clone --mirror https://github.com/you/prj | ||
+ | cd prj.git | ||
+ | # HTTP URL http://gitlab.example.com/you/prj.git | ||
+ | git remote add gitlab git@git.albertleadata.org:you/prj.git | ||
+ | git push gitlab --mirror | ||
+ | |||
+ | # Switch local clone to new repo: | ||
+ | git remote remove origin | ||
+ | git remote add origin git@git.albertleadata.org:you/prj.git | ||
+ | git fetch --all | ||
+ | </code> | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ------ | ||
+ | ====== Github ====== | ||
+ | ===== Manage your fork's sync with upstream ===== | ||
+ | * Add the remote, call it "upstream":<code>git remote add upstream https://github.com/whoever/whatever.git</code> | ||
+ | * Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:<code>git fetch upstream</code> | ||
+ | * Make sure that you're on your master branch:<code>git checkout master</code> | ||
+ | * Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:<code>git rebase upstream/master</code>//Alternately, you could do a ''git merge upstream/master'', but a rebase is most sane, especially for keeping pull requests well-behaved // | ||
+ | |||
+ | ====== Advanced Topics ====== | ||
+ | ===== Locking master branch ===== | ||
* In ./git/hooks/update before section # --- Config:<code> | * In ./git/hooks/update before section # --- Config:<code> | ||
if [ "$refname" == "refs/heads/master" ]; then | if [ "$refname" == "refs/heads/master" ]; then | ||
Line 44: | Line 76: | ||
* Edit .git/description | * Edit .git/description | ||
- | ==== Misc: set active branch in bare repo ==== | + | ====== Miscellaneous Topics ====== |
+ | ===== Set active branch in bare repo ===== | ||
''git symbolic-ref HEAD refs/heads/thebranch'' | ''git symbolic-ref HEAD refs/heads/thebranch'' | ||
+ | ===== Installing git-lfs on Ubuntu ===== | ||
+ | * Some basic pre-requisites: <code>apt install software-properties-common</code> | ||
+ | * Set up repository: <code>curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash</code> | ||
+ | * Install from repository: <code>apt install git-lfs</code> | ||
+ | * Each user will need to do: ''git lfs install'' | ||
+ | |||
+ | |||
+ | ===== Git Service over HTTP/HTTPS ===== | ||
+ | ==== ... for Apache ==== | ||
+ | First //(as root)//:<code> | ||
+ | mkdir -p /var/www/git | ||
+ | chown msamud1:apache /var/www/git | ||
+ | chmod 2750 /var/www/git | ||
+ | chcon -t httpd_sys_content_t /var/www/git | ||
+ | </code> | ||
+ | Then, create auth file with something like: ''htpasswd -c /var/www/git/.htpasswd git'' //... prompted for password// | ||
+ | |||
+ | === For anonymous read/write ... === | ||
+ | In ''/etc/httpd/conf.d/git.conf'':<code> | ||
+ | # Git-smart HTTP/HTTPS back-end | ||
+ | SetEnv GIT_PROJECT_ROOT /var/www/git | ||
+ | SetEnv GIT_HTTP_EXPORT_ALL | ||
+ | ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ | ||
+ | |||
+ | <Directory "/usr/libexec/git-core"> | ||
+ | Options +ExecCGI | ||
+ | Require all granted | ||
+ | </Directory> | ||
+ | |||
+ | <LocationMatch "^/git/.*/git-receive-pack$"> | ||
+ | Order allow,deny | ||
+ | Allow from all | ||
+ | </LocationMatch> | ||
+ | </code> | ||
+ | |||
+ | |||
+ | === ... or, for anonymous read and authenticated write ... === | ||
+ | In ''/etc/httpd/conf.d/git.conf'':<code> | ||
+ | # Git-smart HTTP/HTTPS back-end | ||
+ | SetEnv GIT_PROJECT_ROOT /var/www/git | ||
+ | SetEnv GIT_HTTP_EXPORT_ALL | ||
+ | ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ | ||
+ | |||
+ | <Directory "/usr/libexec/git-core"> | ||
+ | Options +ExecCGI | ||
+ | Require all granted | ||
+ | </Directory> | ||
+ | |||
+ | <LocationMatch "^/git/.*/git-receive-pack$"> | ||
+ | Order allow,deny | ||
+ | AuthType Basic | ||
+ | AuthName "Git Access" | ||
+ | AuthUserFile /var/www/git/.htpasswd | ||
+ | Require valid-user | ||
+ | # Require group committers | ||
+ | </LocationMatch> | ||
+ | </code> | ||
+ | |||
+ | |||
+ | === ... or, for authenticated read/write ... === | ||
+ | In ''/etc/httpd/conf.d/git.conf'':<code> | ||
+ | # Git-smart HTTP/HTTPS back-end | ||
+ | SetEnv GIT_PROJECT_ROOT /var/www/git | ||
+ | SetEnv GIT_HTTP_EXPORT_ALL | ||
+ | ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ | ||
+ | |||
+ | <Directory "/usr/libexec/git-core"> | ||
+ | Options +ExecCGI | ||
+ | Order deny,allow | ||
+ | AuthType Basic | ||
+ | AuthName "Private Git Access" | ||
+ | AuthUserFile /var/www/git/.htpasswd | ||
+ | Require valid-user | ||
+ | </Directory> | ||
+ | </code> | ||
+ | |||
+ | === ... or, for LDAP authentication ... === | ||
+ | Ensure ''mod_ldap'' is installed, then in ''/etc/httpd/conf.d/git.conf'': | ||
+ | <code> | ||
+ | <Directory "/usr/libexec/git-core"> | ||
+ | Options +ExecCGI | ||
+ | Order deny,allow | ||
+ | AuthType Basic | ||
+ | AuthName "Private Git Access" | ||
+ | AuthBasicProvider ldap | ||
+ | AuthLDAPURL "ldap://cosmos.samudio.net/dc=samudio,dc=net?uid?sub?" | ||
+ | Require valid-user | ||
+ | </Directory> | ||
+ | </code> | ||
+ | |||
+ | === ... Active Directory AuthLDAPURL ... === | ||
+ | <code>AuthLDAPURL "ldap://ad-ldap-prod.uhc.com/dc=ms,dc=ds,dc=uhc,dc=com?sAMAccountName?sub?(objectCategory=person)(objectClass=user)"</code> | ||
+ | |||
+ | === ... add specific location auth ... === | ||
+ | <code> | ||
+ | <LocationMatch "^/git/yourrepo.*"> | ||
+ | ... add same LDAP constructs, except for ... | ||
+ | Require ldap-attribute sAMAccountName="yourlogin" | ||
+ | </LocationMatch> | ||
+ | </code> | ||
\\ | \\ | ||
// Links: [[tech:start|Tech Info]] ... [[tech:devops:start|Devops Info]] // \\ | // Links: [[tech:start|Tech Info]] ... [[tech:devops:start|Devops Info]] // \\ | ||