Tom Roche Monday, May 7, 2012 10:09:29 AM UTC-7
>> How to [easily] overwrite managed files in an existing directory
>> with the latest versions from a remote branch/repo, without merging
>> or whack-n-clone?

as defined @ top of thread

Note again, I'm trying to keep it simple/easy for a group of
(relatively) new adopters who don't self-identify as software

Peter J Weisberg Mon, 7 May 2012 15:35:02 -0700 (PDT)
> git fetch origin
> git reset --hard origin/master

> DON'T use `reset` if there's anything in the local branch history
> that you don't want to lose. `reset` affects the history of the
> current branch, not just the working files.

Belated thanks for that advice! which got us started. Since then
another workflow has evolved, about which I'd appreciate comments/
warnings, especially

* warnings of the form, "under [plausible circumstances], your
  workflow produces [significant harms]"

* pointers to existing tools handle this usecase better

0 User switches remote to the desired repo.

1 User runs bash script (follows my .sig to end of post) to see what
  if any changes have been made in remote.

2 If user wants to adopt changes, s/he does

$ git merge --no-commit [${TARGET}]

Seems to work, but is this likely to "bite back"? or is there
A Better Way(tm) to do this?

TIA, Tom Roche <>---script follows to end of post---

#!/usr/bin/env bash
# adapted from

# TODO: usage
# TODO: add --verbose, turn off echo-ing by default

CURRENT_BRANCH="$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git 
branch | grep '^*' |sed s/\*\ //)"; fi)"

if [[ -z "${CURRENT_BRANCH}" ]]; then
  echo -e 'ERROR: cannot determine current branch'
  exit 1
  if [[ -z "${TARGET}" ]]; then
    TRACKING_REPO="$(git config branch.${CURRENT_BRANCH}.remote)"
    if [[ -z "${TRACKING_REPO}" ]]; then
      echo -e 'ERROR: cannot determine tracking repository'
      exit 2
      REMOTE_BRANCH="$(git config branch.${CURRENT_BRANCH}.merge | sed -e 
      echo -e "REMOTE_REPO=${REMOTE_REPO}"
      echo -e "no TARGET specified by command, using TARGET=${TARGET}"

# payload
echo -e "Incoming changes from TARGET=${TARGET}"
# TODO: only diff if -n $(git log)
for CMD in \
  "git fetch" \
  "git log ..${TARGET}" \
  "git diff ..${TARGET}" \
; do
  echo -e "$ ${CMD}"
  eval "${CMD}"
exit 0

# Note on double dots '..' above from 2nd answer @
# > You can use various combinations of specifiers to git to see your diffs as 
you desire:

# > $ git diff remote/origin   
# > This shows the incoming remote changes as deletions; any commits in your 
local repository are shown as additions.

# > $ git diff ...remote/origin
# > Shows incoming remote changes as additions; the triple-dot excludes changes 
committed to your local repository.

# > $ git diff ..remote/origin
# > Shows incoming remote changes as additions; the double-dot includes changes 
committed to your local repository as deletions (since they are not yet pushed).

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to