-1

Say I have a single script that I want to git. From what I know, I have to create a folder which will contain this script and .git.

  • Is there a way to only have the script itself? This would mean having some sort of header/footer to handle git stuff.
  • If not, another option would be to have a single extra file to handle git.
snugghash
  • 450
  • 3
  • 13
tupui
  • 5,738
  • 3
  • 31
  • 52
  • https://git-scm.com/docs/gitrepository-layout – juzraai Jul 28 '18 at 11:15
  • Maybe if you don't like how Git works you should consider alternative sourcecontrol systems? – JohannesB Jul 28 '18 at 11:23
  • @JohannesB I like git this is why I am trying to see if this can be done. – tupui Jul 28 '18 at 12:00
  • @juzraai what do you want to say? – tupui Jul 28 '18 at 12:01
  • I'd assume the down votes are signaling the question shows too few research on the subject before asking. Also, you don't give any context to your question, which leads right into [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) territory... – Romain Valeri Jul 28 '18 at 12:41
  • @RomainVALERI well no. In this case, there is no bigger picture at all. I was just doing some gists and saw that if I cloned it, it created a git folder for it. So I was wondering about an alternative (not github related, I wanted to do this with my git server). And even if it was an XY, remember that sometimes you just don’t have the choice ;) (ex. Your boss obliged you to, huge legacy code base, etc.). So before downvoting, it’s always better to ask for more info as SO guidelines advise. This is what makes a nice and welcoming community =) – tupui Jul 30 '18 at 22:25
  • @Y0da I can understand that, I was just trying to help you figure why people had downvoted (which I did not). – Romain Valeri Jul 31 '18 at 00:00
  • @RomainVALERI no problem :) – tupui Jul 31 '18 at 05:56

2 Answers2

1

One way to achieve a version controlled single-file-in-otherwise-empty-repo is to have a bare repo somewhere, and then check it out to the folder in which you want only a single file.

As explained here

To checkout everything from your HEAD (not index) to a specific out directory:

git --work-tree=/path/to/outputdir checkout HEAD -- .

Community
  • 1
  • 1
snugghash
  • 450
  • 3
  • 13
  • That should do the trick. This way I can have a folder with several scripts. Each of the scripts being under a different git. – tupui Jul 28 '18 at 17:31
0

The .git is integral to the way git works and stores information. You would need it in some way to use git.

If I understand you correctly, you want a script under version control but the folder the script is contained in must be empty.

To that end, we could create a git repository in the parent folder, with the subdirectory having nothing but the script.

parentDirectoryUnderVC/
    .git/
    myScriptProjectWithOnlyMyScriptInIt/
        myScript.whatever
snugghash
  • 450
  • 3
  • 13