Subject: Re: How to update? (git Changed but not updated)

From: Rainer Blome <[email-masked]>
Date: Sun, 22 Feb 2009 02:32:22 +0100

Reto S. News wrote:
> Beginner question: "How to update the pushed changes on the master?"

> # git status # Shows me correctly foo.txt has been changed by the"Slave"

No, it shows that the work tree has been left behind with respect to the 
head of master.

Fix this using git checkout master and git reset --hard.

> # git show   # Shows me even the made changes in a diff style!

But probably the wrong way around, showing added lines as removed?

Freshman answer:
Here's what I am doing.

The attached script mygit-test.sh is a simple test of the below work 
flow, with three repositories a (origin), and clones b and c.

Let's calls the "Master" server "Shared", to avoid confusion with any 
"master" branch.

On Shared, do not work in the master branch.
Instead, work in a dedicated local branch, for example 
"central-development".

# Only needed if your working directory and index are not clean:
git stash

git checkout master
git checkout -b central-development

# Only needed if you had to stash above:
git stash apply
# You can now commit any changes
# Once you've safely commited the changes, use: git stash clear

On Slave, do not work in the master branch as well.
Instead, work in a dedicated local branch, for example "slave".

git checkout -b master origin/master  # Ensure a local copy of master exists
git pull origin master # Ensure the new branch is up to date
git checkout -b slave  # Create the local development branch

# Now edit, commit, edit, commit, ...
# Once you want to publish your changes:

# Update local copy of master:
git pull --rebase origin master

# LOOP:
# Merge your changes on top of new master, staying on slave:
git rebase master slave
# Test and review the merged code on slave.

# Update local copy of master, again,
# to make sure it has not changed in the meantime:
git pull --rebase origin master
# If it changed, go to LOOP, otherwise continue below.

# Update local copy of master (this is now fast-forward)
git rebase slave master
# Send changes to master on Shared
git push origin master
# Leave master
git checkout slave

On Shared:
# Update development with respect to changes on master
git rebase master development

Complex?  Yes.
Can it be simplified?  I hope so.

I have written a script that helps to use the work flow described here.
If anyone is interested, please comment.

Good luck, Rainer