git
Topics
- git hooks, pre-commit hook
- custom git merge driver
- Hosting a Repo in a Cloud
- merge vs rebase workflow
- FAQs
And more:
See also gh.
Configs
System level
Aapplied to every user on the system and all their repositories.
- to view,
git config --list --system
(may need sudo) - to set,
git config --system color.ui true
- to edit system config file:
git config --edit --system
Global User level
Specific personally to you, the user.
- to view:
git config --list --global
- to set:
git config --global user.name xyz
- to edit global config file:
git config --edit --global
Repository level
Specific to that single repository.
- to view:
git config --list --local
- to set:
git config [--local] core.ignorecase true
- to edit repository config file:
git config --edit [--local]
View All Settings
Show system, global, and (if inside a repository) local configs:
git config --list
To also show the origin file of each config item:
git config --list --show-origin
To read one particular config:
To get e.g. user.name
:
git config user.name
You may also specify options --system
, --global
, --local
to read that
value at a particular level.
Global Config
Followed Customizing Git Configuration.
git config --global user.name "Alex Sokolsky"
git config --global user.email "asokolsky@gmail.com"
git config --global core.editor /usr/bin/emacs
git config --global core.excludesfile ~/.gitignore_global
git config --global core.pager ''
git config --global push.default current
where ~/.gitignore_global
:
*~
.*.swp
.DS_Store
Handling an Upstream Repo
alex@latitude7490:~/Projects/psmqtt/ > git remote -v
origin https://github.com/asokolsky/psmqtt.git (fetch)
origin https://github.com/asokolsky/psmqtt.git (push)
upstream https://github.com/eschava/psmqtt.git (fetch)
upstream https://github.com/eschava/psmqtt.git (push)
alex@latitude7490:~/Projects/psmqtt/ > git status
On branch typing
Your branch is up to date with 'origin/typing'.
nothing to commit, working tree clean
Just pull from upstream:
alex@latitude7490:~/Projects/psmqtt/ > git pull upstream master
And then push
alex@latitude7490:~/Projects/psmqtt/ > git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/asokolsky/psmqtt.git
a98ddea..52094f3 master -> master
Repo-specific Config
Set repo-specific (non-global) config settings:
git config user.name "Alex Sokolsky"
git config user.email "asokolsky@gmail.com"
git config core.sshCommand "ssh -i ~/.ssh/private_key"
Make sure your private identity is available:
ssh-add ~/.ssh/private_key
Then
git remote add origin git@github.com:asokolsky/repo.git
git push --set-upstream origin master
Importing a file from a different repo
Instead of using git submodules, sometimes this may make more sense:
#!/bin/bash
#
# This will update DST with the latest version of SRC from REPO.
DST=discard_me.cpp
SRC=trash1.cpp
REPO_HOST="git@github.com:asokolsky"
REPO=oddeven
#
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Exit on error inside any functions or subshells.
set -o errtrace
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
# Turn on traces, useful while debugging but commented out by default
#set -o xtrace
# Check syntax with `shellcheck ./goto`
# this repo root
DSTROOT=$(git rev-parse --show-toplevel)
# this one already defined in MacOS
: "${TMPDIR:=/tmp}"
pushd "${TMPDIR}" > /dev/null
echo "Retrieving ${REPO}/${SRC}"
git clone --quiet --no-checkout --depth 1 "${REPO_HOST}/${REPO}.git"
cd $REPO
echo "Overwriting ${DSTROOT}/${DST}"
git show HEAD:$SRC > "${DSTROOT}/${DST}"
popd > /dev/null
rm -rf "${TMPDIR}/${REPO}"