Notes to Self

Alex Sokolsky's Notes on Computers and Programming

git

Topics

And more:

Proprietary Extensions

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

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}"