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

sub-directory repo technique

From
Allan Kelly <allankelly@gmail.com>
Date
Jun 12, 2009, 12:07 UTC
Message-ID
<9586f3420906120507o194fc459l5fbdcd14a7095ae8@mail.gmail.com>
Hi,

I'm quite new to git, but it is serving me well.  The main scenario I am working with is my own code bases with several centralised repos on a server. I clone, develop and push from a various machines, rather than working on the server. Great!

However, for one of my projects I have the following:
* xidebar repo contains perl programs & modules, and a projects/ directory
* Under projects/ are self-contained project trees, eg
projects/westbarnsgala.info
* The total size is quite large and it's undesirable to clone the
whole thing remotely
* I want to be able to remote clone, edit, and push just a specific
projects/westbarnsgala.info tree

I have a solution which works fine for me below. I wonder if this is recommended however, or whether there's "another way to do it"? Probably!

With xidebar as the 'parent' repo on the "rss_rand" server for tracking all xidebar contant together, I then go into the individual project/proj1 dirs and create a repo there. I can then remotely clone this repo, edit and push as below.

Here's the blow-by-blow description.

(I need the top-level .gitignore to contain a line '.gitignore' to avoid reporting the "sub-repo" .gitignore as untracked - which is correct but not of interest. It appears that git automatically ignores the .git dir for the westbarnsgala.info repo created below)

On rss_rand server:
With previously created xidebar/ repo:
* add line '.gitignore' in xidebar/.gitignore
1. Create westbarnsgala.info repo
* cd projects/westbarnsgala.info
* git init
* git add .
* git commit -a -m 'initial commit'
2. On other machine: Clone, edit, commit locally and push changes remotely
* cd projects
* git clone rss_rand:~/xidebar/projects/westbarnsgala.info/ wbg
* cd wbg
* vi htmlgen.xml
* commit -a -m 'a smalll update'
* git push origin
3. On rss_rand: Update local files with remote changes from local repo
* => The git repo is up to date with the remote edit.
* => The files are not.
* => A checkout reports the mis-match and bails.
* => So force it.
* git checkout -f
* => Now the files are up to date!
Now 'git status' on either machine shows things are up to date.
4. Now, back to the rss_rand xidebar repo: commit changes.
* cd ../..
* git status => Shows changes detected correctly
* git commit -a -m 'update to westbarnsgala.info'
Routine of work is now:
Edit on laptop.
* => If in doubt, start with a 'git pull' (Which does both fetch and merge).
* commit -a -m 'a message'
* git push
Publish from rss_rand (overnight cron script):
* cd xidebar/projects/westbarnsgala.info
* git status => Just to check
* git checkout -f
* cd ../..
* ./xidebar westbarnsgala.info && ftp_dir_diff westbarnsgala.info
Cheers, al.
Next: Avery Pennarun
Message 1 of 2 in “sub-directory repo technique”
  1. Allan KellyJun 12, 2009
  2. Avery PennarunJun 16, 2009

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.