Follow

Any needs out there? I need your help please...

So, let’s say I have a repo that contains a folder called “example”. There are many other files and folders in this repo too.

Is it possible for me to run a git push command that ONLY pushes the contents of example to the root of the remote git repo?

So after I push /example/test.txt to my remote repo, it would be test.txt world be in the root of the repo, not /example.

@kev sounds like you want a submodule or sub tree, actually. You can’t have different paths across repo clones, though, so you can’t do this unless you specifically set up the remote as just the example folder’s contents.

@kev Also, either way you go will be complicated if your commits that change example/ also changed other paths. So much so that you might want to start your remote afresh, and then import the sub(module|tree) back into your first one, which would erase your history, alas.

@kev
Depends on the purpose, I'd say.
If you want to have this structure only at the repo, but not local (for whatever reason), then you could cp or mv the folder contents to the root, commit + push, and then revert that commit.

Of course the next commit+push would revert it altogether. So the reason for this would be worth to know.

@kev so, wait, are you just trying to push all of the content living locally inside of said folders to the repo root? (in other words, directory structure lives on your local machine, but not in the repo?)

So Folder1/Example1.txt and Folder2/Example2.txt show up at the root as Example 1 and Example 2, no directories?

It almost sounds like you're trying to use git as a non-hierarchial file sync.
@kev if the answer is yes...one way to do this might be to do a git init inside of each directory, with each one pointing to the repo.

Just don't ever git pull, or that directory would get all the repo's content dumped in. But if you're only pushing, I don't see why it wouldn't get the desired result.
@kev @sean The best way to do this is with git sub-modules, so that a repo can contain other repos. See git-scm.com/book/en/v2/Git-Too…

But it is finicky and introduces complexity. The best course may be to change the workflow if possible.

@kev In short, no.

Your local repo is (presumably) a clone of that remote, so it doesn't make sense to think of making a change to the remote that isn't reflected in your local.

If you can make commits that get your local into the desired state, then of course you can push them, but if that fit your use case I presume you'd be doing that.

You might need to say more about your workflow, in order to get to a question that meets your need and works with Git with reasonable simplicity.

@kev one way is sub modules, another is filter-branch on a temp branch and push that

@kev the latter is only really technically possible for what you want, not practically usable.

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.