threads / discuss / 43874

Working from different machines.

Subject: Working from different machines.

## tl;dr

7 messages between Aug 17, 2016 and Aug 19, 2016.

replies: 6people: 4as markdown or json

Tobiah· Aug 17, 2016, 21:47 UTC · lore

Right now I have a server at work where I keep a bare repository as a source and backup for projects. So I clone a project from there to my desktop, and work, making a few branches as I try out ideas for new features.

Then I go home, and I want to work as though I was sitting at my desktop. If I clone the committed work, I don't get all my branches. How can I work so that I now easily have all my branches, then after I work at home, when I go back to my desktop, the branches now reflect whatever state I last left them in?

In other words, I want to work from different machines, and always sit down to the environment exactly as I last left it.

Thanks!
Junio C Hamano· Aug 17, 2016, 22:41 UTC · re: Tobiah · lore

Re: Working from different machines.

Tobiah <toby@tobiah.org> writes:
> In other words, I want to work from different machines, and always
> sit down to the environment exactly as I last left it.

You have several options, but it depends on untold expectations you have beyond "exactly as I last left it." So the following is only to show directions and possibilities without going into details.

For example, do you save all changes you made in your editor buffers before you leave the 'desktop'? If the answer is "no", then that is not a problem Git-the-tool is interested in solving, and the only solution I could think of is to use mechanism to share the session between 'desktop' and 'home', using things like remote-desktop or screen session.

If the answer is "yes", the next question is if you commit all the changes you made before you leave the 'desktop'. If the answer is "no", again, that is not a problem Git-the-tool is interested in solving, and the only solution I could think of (in addition to the "share the session" above) is to use networked filesystem shared between 'desktop' and 'home'.

If the answer is "yes", then you are in the problem space that Git-the-tool is interested in solving. Assuming that you have network connection into 'desktop' from 'home', the solution would involve making it the first thing to do when get home to run "git fetch" on 'home' to get the latest state from the 'desktop', and run "git push" on 'home' to push out the latest state to the 'desktop' before you leave 'home'. If your 'server' is for your sole use, and if 'home' has network connection into 'server', then you could instead rendezvous at 'server' by running "git push server" on 'desktop' (or 'home') to 'server' as the last thing before you leave 'desktop' (or 'home'), and running "git fetch server" on 'home' (or 'desktop') as the first thing before you start working on 'home' (or 'desktop').

Jacob Keller· Aug 18, 2016, 06:10 UTC · re: Junio C Hamano · lore

Re: Working from different machines.

On Wed, Aug 17, 2016 at 3:41 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> If the answer is "yes", then you are in the problem space that
> Git-the-tool is interested in solving.  Assuming that you have
> network connection into 'desktop' from 'home', the solution would
> involve making it the first thing to do when get home to run "git
> fetch" on 'home' to get the latest state from the 'desktop', and run
> "git push" on 'home' to push out the latest state to the 'desktop'
> before you leave 'home'.  If your 'server' is for your sole use, and
> if 'home' has network connection into 'server', then you could
> instead rendezvous at 'server' by running "git push server" on
> 'desktop' (or 'home') to 'server' as the last thing before you leave
> 'desktop' (or 'home'), and running "git fetch server" on 'home' (or
> 'desktop') as the first thing before you start working on 'home' (or
> 'desktop').
>
>

To add to this, you may need to modify the "git push" portion of the phases and the "git fetch" potion to include all the branches you are interested in.

Thanks, Jake

Jakub Narębski· Aug 18, 2016, 12:29 UTC · re: Junio C Hamano · lore

Re: Working from different machines.

W dniu 18.08.2016 o 00:41, Junio C Hamano pisze:
> Tobiah <toby@tobiah.org> writes:
Show 16 quoted lines
> [...] the next question is if you commit all the
> changes you made before you leave the 'desktop'. [...]
> 
> If the answer is "yes", then you are in the problem space that
> Git-the-tool is interested in solving.  Assuming that you have
> network connection into 'desktop' from 'home', the solution would
> involve making it the first thing to do when get home to run "git
> fetch" on 'home' to get the latest state from the 'desktop', and run
> "git push" on 'home' to push out the latest state to the 'desktop'
> before you leave 'home'.  If your 'server' is for your sole use, and
> if 'home' has network connection into 'server', then you could
> instead rendezvous at 'server' by running "git push server" on
> 'desktop' (or 'home') to 'server' as the last thing before you leave
> 'desktop' (or 'home'), and running "git fetch server" on 'home' (or
> 'desktop') as the first thing before you start working on 'home' (or
> 'desktop').
Two additional comments:
* First, `--mirror` might be what the relation between 'desktop'
  and 'home' repositories should be.
* Second, even if you can connect only from 'home' to 'desktop',
  but not from 'desktop' to 'home', the refspec mechanism of Git
  is flexible enough that you can emulate 'push' with 
  appropriately configured 'fetch', and vice versa.
-- 
Jakub Narębski
Tobiah· Aug 18, 2016, 14:28 UTC · re: Jakub Narębski · lore

Re: Working from different machines.

>
> * First, `--mirror` might be what the relation between 'desktop'
>   and 'home' repositories should be.
>
Here's what I'm trying, am I in the right ballpark?
desk> git branch
* master
desk> git checkout -b banana
Switched to a new branch 'banana'
desk> echo 'message' > oracle
desk> git add oracle
desk> git commit -a -moracle
[banana 66e7823] oracle
  1 file changed, 1 insertion(+)
  create mode 100644 oracle
desk> git push --mirror
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 260 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To toby@shells.rcsreg.com:/home/git/toby/exposmart
  * [new branch]      banana -> banana
# Then on another machine:
home> git branch
* master
## Forgot to 'pull' here, but it never shows new branches anyway
## I have to get them by name.  Can I automate that?
home> git checkout banana
Branch banana set up to track remote branch banana from origin.
Switched to a new branch 'banana'
home> cat oracle
message
home> echo 'other message' >> oracle
home> git commit -a -moracle2
[banana 78e6c45] oracle2
  1 file changed, 1 insertion(+)
home> git push --mirror
Counting objects: 36, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (36/36), 2.90 KiB | 0 bytes/s, done.
Total 36 (delta 13), reused 14 (delta 4)
To shells.rcsreg.com:/home/git/toby/exposmart
    66e7823..78e6c45  banana -> banana
    7e01bf8..c65ed75  origin/HEAD -> origin/HEAD
  * [new branch]      origin/auto -> origin/auto
  * [new branch]      origin/banana -> origin/banana
  * [new branch]      origin/develop -> origin/develop
  * [new branch]      origin/flipper -> origin/flipper
  * [new branch]      origin/tart -> origin/tart
home> vi
home> git push --mirror
Total 0 (delta 0), reused 0 (delta 0)
To shells.rcsreg.com:/home/git/toby/exposmart
    66e7823..78e6c45  origin/banana -> origin/banana
home> git push --mirror
Everything up-to-date
home>

## Why do I have to push three times to get the 'Everyting up-to-date' ## message? Why does it still mention 'flipper' and 'tart' and all ## other branches I've played with. When I delte them locally, I want ## them to be deleted everywhere. They just keep accumulating. ## ## Now back a the other machine

desk> git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
 From shells.rcsreg.com:/home/git/toby/exposmart
    66e7823..78e6c45  banana     -> origin/banana
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
     git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
     git branch --set-upstream-to=origin/<branch> banana
desk> git branch
* banana
   master
desk> git pull origin banana
 From shells.rcsreg.com:/home/git/toby/exposmart
  * branch            banana     -> FETCH_HEAD
Updating 66e7823..78e6c45
Fast-forward
  oracle | 1 +
  1 file changed, 1 insertion(+)
desk> cat oracle
message
other message

## So it seems to have worked, but the more I go back and forth ## The more I seem to have eventual problems getting branches ## and changes. Am I doing it right?

Thanks
Jakub Narębski· Aug 18, 2016, 16:53 UTC · re: Tobiah · lore

Re: Working from different machines.

W dniu 18.08.2016 o 16:28, Tobiah pisze:
> ## [...]  Why does it still mention 'flipper' and 'tart' and all
> ## other branches I've played with.  When I delte them locally, I want
> ## them to be deleted everywhere.  They just keep accumulating.

In case of non-mirror setup. Git wouldn't delete remote-tracking branches (e.g. origin/tart) if branch in remote repository is deleted (e.g. tart in origin repository); you need to prune (or set up to auto prune), e.g.

 $ git remote origin prune
-- 
Jakub Narębski
Tobiah· Aug 18, 2016, 14:11 UTC · re: Junio C Hamano · lore

Re: Working from different machines.

On 08/17/2016 03:41 PM, Junio C Hamano wrote:
Show 37 quoted lines
> Tobiah <toby@tobiah.org> writes:
>
>> In other words, I want to work from different machines, and always
>> sit down to the environment exactly as I last left it.
>
> You have several options, but it depends on untold expectations you
> have beyond "exactly as I last left it."  So the following is only
> to show directions and possibilities without going into details.
>
> For example, do you save all changes you made in your editor buffers
> before you leave the 'desktop'?  If the answer is "no", then that is
> not a problem Git-the-tool is interested in solving, and the only
> solution I could think of is to use mechanism to share the session
> between 'desktop' and 'home', using things like remote-desktop or
> screen session.
>
> If the answer is "yes", the next question is if you commit all the
> changes you made before you leave the 'desktop'.  If the answer is
> "no", again, that is not a problem Git-the-tool is interested in
> solving, and the only solution I could think of (in addition to the
> "share the session" above) is to use networked filesystem shared
> between 'desktop' and 'home'.
>
> If the answer is "yes", then you are in the problem space that
> Git-the-tool is interested in solving.  Assuming that you have
> network connection into 'desktop' from 'home', the solution would
> involve making it the first thing to do when get home to run "git
> fetch" on 'home' to get the latest state from the 'desktop', and run
> "git push" on 'home' to push out the latest state to the 'desktop'
> before you leave 'home'.  If your 'server' is for your sole use, and
> if 'home' has network connection into 'server', then you could
> instead rendezvous at 'server' by running "git push server" on
> 'desktop' (or 'home') to 'server' as the last thing before you leave
> 'desktop' (or 'home'), and running "git fetch server" on 'home' (or
> 'desktop') as the first thing before you start working on 'home' (or
> 'desktop').
>

I've done a poor job of expressing my need. I'm only speaking about the state of each git project directory. Shared sessions or filesystems are not what I'm loolking for.

As far as the master branch goes, I have no problem syncing everything to the server, then pulling to a different machine. When I said I want everything to be the same between the home and work machines, I meant with regard to all of the other branches. I want to easily create an entire movable git environment that is indistinguishable from machine to machine.

It looks like --mirror is close to what I am looking for.
Thanks

← back to recent threads