1

Context

I want to keep track of the history of a local script in a project root folder using git, but I do not want to push it on remote.

Therefore, this file is now referenced in my .gitignore file, so it is not tracked locally.
But I would like to track it on my local machine (while always keeping the remote without this file).

Ideas

This seemed to be a solution; Track files in local Git repo but ignore in remote but it needs the creation of a subfolder, which I don't want to create for different reasons, and thus keeping all my script files at the root of my folder.

Question

Is there a simple way to do so?

swiss_knight
  • 5,787
  • 8
  • 50
  • 92

2 Answers2

0
  1. Create new branch without remote tracking
  2. Delete ignored files from .gitignore
  3. Commit local branch
  4. You can set hook to automate commits to local branch

When you commit main branch, you just need to merge this commit to local branch. All changes to local tracked files you should do on local branch.

Leszek Mazur
  • 2,443
  • 1
  • 14
  • 28
0

I think your best choice is making it into a submodule but as you already mentioned that's not an option, my best bet would be doing it using Git hooks (haven't tried tho').

If you can add a pre-receive or post-receive hook then you could do something similar to this but instead of rejecting you could remove the files from the commit and amend it.

Again, not even sure if this is possible as that would create a new commit and hash and pulling from the same branch wouldn't be possible as references would be totally different. You would need to always push like git push origin local_branch:remote_branch for it to even make sense.

Felipe Cabargas
  • 1,006
  • 7
  • 10