User Tools

Site Tools


tech:devops:git

This is an old revision of the document!


General Git Topics

Basic Config

git config --global user.name 'Your Name'
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'

Some history/view tips

  • Show files involved in a particular commit:
    git diff-tree --no-commit-id --name-only -r commitid
  • Show basic history for a file:
    git log --all -- path/to/file.ext
  • Show all pull/push activity:
    git reflog show --date=iso origin/master
  • Show commit hash and comment
    git log --abbrev-commit --pretty=oneline 228d0ae de36d78
    git log --pretty=oneline 228d0ae de36d78
  • Show everything in the commit for hash
    git show d9ekhg9alk239d94dkd949dksc0dkgkls90fds93
  • Show commit info for hash
    git show d9ekhg9alk239d94dkd949dksc0dkgkls90fds93 | head -6
  • Show files changed for commit
    git show d9ekhg9alk239d94dkd949dksc0dkgkls90fds93 | grep "^diff --git"

Rename a tag

git tag new old
git tag -d old
git push origin :refs/tags/old
git push --tags

The colon in the push command removes the tag from the remote repository. If you don't do this, git will create the old tag on your machine when you pull.

Ensure that the other developers/users remove the deleted tag by running the following command:

git pull --prune --tags



GitLab

Import Project into Gitlab

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



Github

Manage your fork's sync with upstream

  • Add the remote, call it “upstream”:
    git remote add upstream https://github.com/whoever/whatever.git
  • Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:
    git fetch upstream
  • Make sure that you're on your master branch:
    git checkout master
  • 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:
    git rebase upstream/master

    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:
    	if [ "$refname" == "refs/heads/master" ]; then
    		if [ "$USER" != "<someadminuser>" ]; then
    			echo "POLICY: you are not allowed to change the master branch !"
    			exit 1
    		else
    			echo "POLICY: $USER allowed to change the master branch ..."
    		fi
    	fi
  • git config receive.denyCurrentBranch ignore
  • Edit .git/description

Miscellaneous Topics

Set active branch in bare repo

git symbolic-ref HEAD refs/heads/thebranch

Installing git-lfs on Ubuntu

  • Some basic pre-requisites:
    apt install software-properties-common
  • Set up repository:
    curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
  • Install from repository:
    apt install git-lfs
  • Each user will need to do: git lfs install


Links: Tech InfoDevops Info

tech/devops/git.1533438290.txt.gz · Last modified: 2018/08/04 22:04 by rk4n3