Home > Back-end >  Git how to find or add .gitignore
Git how to find or add .gitignore

Time:10-22

I am having a problem adding the text file .gitignore in my terminal session. I open the command line prompt and navigate to the folder that holds the .gitignore file and a hello_git.py file.

When I type git status; the Python file shows up but not the .gitignore. I can add the Python file, by typing git add . The other file will not add or commit.

What should I be doing in order to use the .gitignore file?

CodePudding user response:

Here is a quick introduction on how to use the same gitignore globally to all your projects if ever you would be interested in it as you were not too deep in your explanation:

touch ~/.gitignore_global # This creates a global.gitignore file in the current directory.

git config --global core.excludesfile ~/.gitignore_global # This command will override all patterns in /.gitignore global in all situations.

# Following this do not forget to edit the .gitignore_global

However, as far as I can tell, you cannot push your own .gitignore file. Given that, I would like you to double-check that the content is not empty, and if it is, please update it before looking at your git status (as @evolutionxbox also stated). Additionally, attempt to include it in your commit; if that does not work, you can force it, but this is never a great recommendation:

git add --force [...]/.gitignore

#
# Man git add:
# -f, --force Allow adding otherwise ignored files.
# https://git-scm.com/docs/git-add
#

Cheers, I hope this helps; remember to agree with the solution if it works for you. Have a wonderful day,

Simon.

  •  Tags:  
  • git
  • Related