MEM
MEM

Reputation: 31337

How to a add a file when a .gitignore is already present on that folder?

As I've been told, git doesn't recognize folders de per se. In order to have the folder to be on the repo, but not the files inside we did create a .gitignore file inside that folder with the following inside:

# Ignore everything in this directory
*
# Except this file
!.gitignore

It happens however that, inside that directory, we now need to add a new file that SHOULD be tracked by the git.

How can we proceed ?

Should we, do the steps on the following order ?

  1. Change to:

    # Ignore everything in this directory
    *
    # Except this file
    !.gitignore
    !mynewfile.php
    
  2. git add mynewfile.php

  3. git commit -a -m "added new file inside specific folder"

  4. git push (so that my remote hub knows about this and syncs with master so that all stay equal).

Or, should we proceed differently ?

Upvotes: 1

Views: 245

Answers (2)

CharlesB
CharlesB

Reputation: 90336

The steps you suggest are OK, but step 1) is unneeded as there's no need to change your .gitignore file, just add it with --force flag and commit it.

Listing files in .gitignore tell git that they are meant to be untracked, but it doesn't prevent you to track them. It applies only to untracked files, there's nothing wrong into having tracked files listed in it.

Upvotes: 1

linquize
linquize

Reputation: 20386

git add -f the_ignored_file

Allows you to add ignored file.

Upvotes: 1

Related Questions