git
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 ''
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}"
More
FAQs
Undo the last local commit
git reset HEAD~