threads / discuss / 17941

How to update? (git Changed but not updated)

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

## tl;dr

4 messages between Feb 21, 2009 and Feb 22, 2009.

replies: 3people: 4as markdown or json

Reto S. News· Feb 21, 2009, 21:23 UTC · lore
Beginner question: "How to update the pushed changes on the master?"

As a proof of concept to switch from CVS to git I prepared an environment on two servers. I call the one "Slave" and "Master" the other. Almost everything is working besides a silly "cvs update" functionality I couldn't still find out after hours.

On Slave Host (a Developer that receives a working copy of a project):

$ git clone git://master.example.net/test myrepo $ cd myrepo # ... here I see all received files from the master $ Changing file "foo.txt" $ git add . # ... for whatever reason this is necessary $ git commit -m 'I changed this file' $ git push

On Master Host (master.example.net):

# git status # Shows me correctly foo.txt has been changed by the"Slave" # git show # Shows me even the made changes in a diff style!

Now I have to update the fresh content produced by the "Slave". As an ugly work-around, I'm currently cloning it again from localhost :-|

Any suggestions are very appreciated.
--reto
Sitaram Chamarty· Feb 22, 2009, 01:10 UTC · re: Reto S. News · lore

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

On 2009-02-21, Reto S. News <retoh@dplanet.ch> wrote:
Show 15 quoted lines
> Beginner question: "How to update the pushed changes on the master?"
>
> On Slave Host (a Developer that receives a working copy of a project):
>
> $ git clone git://master.example.net/test myrepo
> $ cd myrepo   # ... here I see all received files from the master
> $ Changing file "foo.txt"
> $ git add .   # ... for whatever reason this is necessary
> $ git commit -m 'I changed this file'
> $ git push
>
> On Master Host (master.example.net):
>
> # git status # Shows me correctly foo.txt has been changed by the"Slave"
> # git show   # Shows me even the made changes in a diff style!
I'll bet the changes shown are 'reversed'...
> Now I have to update the fresh content produced by the "Slave". As an
> ugly work-around, I'm currently cloning it again from localhost :-|
>
> Any suggestions are very appreciated.

Your master is a non-bare repo. Try http://git.or.cz/gitwiki/GitFaq#non-bare .

I also wrote up a much more detailed description of this at http://sitaramc.github.com/concepts-and-tips/0-terminology.html#a5 -- I hope it helps you.

Regards,
Sitaram
Rainer Blome· Feb 22, 2009, 01:32 UTC · re: Reto S. News · lore

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

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
Reto Schär· Feb 22, 2009, 10:07 UTC · re: Reto S. News · lore

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

Sorry. The final counterpart of a "cvs update" was a simple "git pull".
# Almost too much documentation available for such simple scenarios ;_)

-- Reto S. News <retoh <at> dplanet.ch> writes:

← back to recent threads