0

I have a git repo that I am autogenerating. I want to push these autogenerated files to a remote git repo, however, I dont want to keep the files. Currently I am doing the fallowing :

git clone git@server:repo
rm -r *     # this does not remove .git, so history will stay
#code for auto generation here
git add.
git commit -m "auto geenrated commit"
git push origin master

As you can see I only need .git folder, Is there a way to pull only .git folder, Or better, is there a way to push current folder to a repo as a new commit ? To be clear, I dont want to remove or edit history (because I am using this auto generated files as a submodule in another project, so certain commits needs to stay).

numan
  • 71
  • 1
  • 4
  • there is a typo, "rm -r" should be "rm -r *" – numan Jan 06 '21 at 08:19
  • 2
    Then [edit] the question. – jonrsharpe Jan 06 '21 at 08:21
  • But no, the `*` glob won't include files or directories with a leading `.` by default, see e.g. https://stackoverflow.com/q/19363795/3001761. – jonrsharpe Jan 06 '21 at 08:27
  • yes thank, you i did not see the edit button, now I edited. Also yes I do not want the .git to be removed, whole point is I need the history but not the actual files, so I remove them and dont touch .git . I edited question aain to make it more obivious – numan Jan 06 '21 at 09:40
  • 1
    "*Is there a way to pull only .git folder*" [`git clone -n`](https://git-scm.com/docs/git-clone#Documentation/git-clone.txt--n) – phd Jan 06 '21 at 13:22
  • "*Or better, is there a way to push current folder to a repo as a new commit ?*" My advice is to learn about [shallow clone](https://stackoverflow.com/search?q=%5Bgit%5D+shallow+clone) + [sparse checkout](https://stackoverflow.com/search?q=%5Bgit%5D+sparse+checkout). `git clone --depth=1 -n` + [`git sparse-checkout`](https://git-scm.com/docs/git-sparse-checkout). – phd Jan 06 '21 at 13:26
  • @phd `git clone --depth=1 -n` is the answer I was looking for. Should I write an answer and mention you? – numan Jan 07 '21 at 13:58
  • 1
    https://stackoverflow.com/search?q=%5Bgit%5D+clone+only+%22.git%22+directory – phd Jan 07 '21 at 15:31

0 Answers0