git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Newbie problem

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 28, 2007, 08:01 UTC
Message-ID
<7vmyxht0r6.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<87vec5vvt5.fsf@osquare.oqube.com>
Insitu <abailly@oqube.com> writes:
Show 10 quoted lines
> Now, I want to be able to do:
> lap> git push
> or
> lap> git pull
>
> instead of 
> lap> git push ssh://pc/~/.git
>
> I think I need to reconfigure my remote branches/origin on laptop but
> don't want ot break everything.

The necessary syntax and configuration files are all documented fairly detailed in the manual pages, but it is a tad hard to know where to look:

    http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html
    http://www.kernel.org/pub/software/scm/git/docs/git-push.html
    http://www.kernel.org/pub/software/scm/git/docs/git-config.html

If you use recent enough git (post 1.5.0), the recommended way to keep two boxes in sync is:

On mothership box, in .git/config:
 [remote "origin"]
     url = satellite:.git/
     fetch = +refs/heads/*:refs/remotes/origin/*
     push = refs/heads/*:refs/remotes/origin/*
 [branch "master"]
     remote = origin
     merge = refs/heads/master
On satellite laptop, in .git/config:
 [remote "origin"]
     url = mothership:.git/
     fetch = +refs/heads/*:refs/remotes/origin/*
     push = refs/heads/*:refs/remotes/origin/*
 [branch "master"]
     remote = origin
     merge = refs/heads/master
Then, whenever you start working on the satellite:
	$ git pull

which, while you are on "master" branch, would use 'origin' as the default remote (thanks to branch.master.remote configuration), store the copy of mothership's branches in refs/remotes/origin/, and merges the "master" branch obtained from the mothership to your "master" branch on the satellite [*1*].

When you are done working on the satellite:
	$ git push

will push to "origin" by default, which would push all your branches (thanks to remote.origin.push configuration) to mothership's refs/remotes/origin/.

When you go back to the mothership, your work done on the satellite are already pushed into the refs/remote/origin/ tracking branches, so you can merge them in (you can do this after shutting down your satellite laptop, which is the beauty of this setup):

	$ git merge origin/master
to merge in the changes you did on the satellite.
[Footnote]
*1* If you prefer to keep a straight history, you may want to
    fetch+rebase instead of pull which is a fetch+merge, in
    which case this step will be:
	$ git fetch
        $ git rebase origin/master
Previous: InsituNext: Insitu
Message 2 of 3 in “Newbie problem”
  1. InsituJul 28, 2007
  2. Junio C HamanoJul 28, 2007
  3. InsituJul 28, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.