How to get Git to exclude local directory from PUSH to remote but still part of local repo

Using git, I would like to be able to store a specific folder as part of my local project (use it in branches, etc.), but I do not want this directory to fall into a public git server.

In this folder there are some Java CLI materials that the project does not need, but I would like to maintain synchronization with the work of the branch, which will work live.

Is it possible?

+4
source share
3 answers

A very short answer is not . Here's why: When your local git branch is redirected to the server, it is pushed as without any exceptions. Since commit contains files, this can ruin git internally if some files are not clicked. This selective behavior is not supported, and I think it will never happen, since most of the time you use git incorrectly when you need such materials.

However, there are many ways:

  • The first is just adding material to the repo. You obviously need this, and you want it to be versioned, so from my point of view, all that is needed to add files to git.
  • You can try git -submodules, but this will also add files to your repo. Your java cli will be a different repository and your original repo will track versions.
  • You could tell git to ignore the subfolder than create a java-cli repository, and only two without any interaction.

I would definitely go with 1, because when I need something for a project, then it belongs to the repo, even if it is java cli.

+1
source

If you do not need to track these files at all ...

... you can do git ignore .

If you want to track them locally ...

... but don't have them in the remote repo. I can only give you some tips / ideas for a thing I have never tried , but you will probably end up with different repositories and things,> a little disgusting.

I would look at (from, perhaps, to the level of a probably pretty dirty and bad idea):

  • Nested Repositories
  • Delete when pressed : (Disadvantage: you probably won’t be able to distinguish correctly, since the stories correspond only to the temporary repository. You could , of course, hack your difference in one way or another, which makes the configuration even more dirty.)
    • Steps:
      • Before you click the clone repository button in a temporary folder
      • Delete your subfolder from the whole story inside the newly created clone (getting a different repository with different hashes commit)
      • Click the newly created repository.
    • Options: Trigger:
    • Options: Delete:

Again: I have not used any of them , but do not know my flaws, traps, etc. , but it seems to me that subtrees are the best solution of the above.

Most of the rest makes me pretty dirty, but at the end of the day , only what works for you is important .

The ship is lousy, but the ship.

... whether in Wasabi

0
source

Even shorter answer: YES!
Now this is a function on github. You can exclude file types using gitignore.
https://help.github.com/articles/ignoring-files/
I personally exclude a file directory called ASSETS from all of my repositories by adding the following to my global gitignore file:
ASSETS / *
Example:

 # Compiled source # ################### *.com *.class *.dll *.exe *.o *.so # Packages # ############ # it better to unpack these files and commit the raw source # git has its own built in compression methods *.7z *.dmg *.gz *.iso *.jar *.rar *.tar *.zip # Logs and databases # ###################### *.log *.sql *.sqlite # OS generated files # ###################### .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes ehthumbs.db Thumbs.db # Audio Files # ############### *.wav *.mp3 *.wma # Video Files # ############### *.wmv *.mpg *.mpeg *.mp4 *.mov *.flv *.avi *.ogv *.ogg *.webm # Image Files # ############### *.jpg *.gif *.png *.svg *.ico # Folders # ########### ASSETS/* # Documents # ############# *.pdf *.doc 


The above file on my linux arch machine is in ~ / .gitignore_global

-1
source

All Articles