1393

I need to add some rules to my .gitignore file. However, I can't find it in my project folder. Isn't it created automatically by Xcode? If not, what command allows me to create one?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Luca
  • 20,399
  • 18
  • 49
  • 70
  • 68
    echo 'xxx' > .gitignore – ybdesire Jun 26 '15 at 05:26
  • 12
    https://www.gitignore.io/ – Ivan Aracki Jul 12 '16 at 15:19
  • 13
    Copy the `.gitignore` file from one of your existing projects. – Suragch Feb 05 '17 at 22:25
  • how about migrating the question to superuser? – Makan Aug 03 '17 at 07:50
  • So they fixed [this apparently!](https://twitter.com/jenmsft/status/1099337661196587008?s=21) – spottedmahn Feb 24 '19 at 02:49
  • Where is the more general question (that is not [Xcode](http://en.wikipedia.org/wiki/Xcode)-specific) - as general Google searches (without Xcode) seems to lead here? – Peter Mortensen Aug 04 '19 at 20:14
  • Some candidates: *[How to ignore certain files in Git](https://stackoverflow.com/questions/4308610)*, *[How do I ignore files in a directory in Git?](https://stackoverflow.com/questions/8527597)*, and *[Git - Creating a .gitignore file](https://stackoverflow.com/questions/11050487)* – Peter Mortensen Aug 04 '19 at 20:24
  • More tool-specific ones: *[How to create a .gitignore file in Windows 10](https://stackoverflow.com/questions/48207907)* and *[How do I ignore all files in a folder with a Git repository in Sourcetree?](https://stackoverflow.com/questions/9665399)* – Peter Mortensen Aug 04 '19 at 20:27
  • https://github.com/czheo/gitignorepy I created this tool several years ago – czheo Mar 16 '23 at 10:38

42 Answers42

1810

If you're using Windows, it will not let you create a file without a filename in Windows Explorer. It will give you the error "You must type a file name" if you try to rename a text file as .gitignore

Enter image description here

To get around this, I used the following steps.

  1. Create the text file gitignore.txt
  2. Open it in a text editor and add your rules, then save and close
  3. Hold Shift, right click the folder you're in, and then select Open command window here
  4. Then rename the file in the command line, with ren gitignore.txt .gitignore

Alternatively, HenningCash suggests in the comments:

You can get around this Windows Explorer error by appending a dot to the filename without an extension: .gitignore.. It will be automatically changed to .gitignore.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ajcw
  • 23,604
  • 6
  • 30
  • 47
625

As simple as things can (sometimes) be: Just add the following into your preferred command-line interface (GNU Bash, Git Bash, etc.)

touch .gitignore

As War pointed out in the comments, touch works on Windows as well as long as you provide the full path. This might also explain why it does not work for some users on Windows: The touch command seems to not be in the $PATH on some Windows versions by default.

C:\> "c:\program files (x86)\git\bin\touch.exe" .gitignore

Note: The path might differ, depending on your setup and installation path.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kaiser
  • 21,817
  • 17
  • 90
  • 110
  • 8
    this didn't work for me, it said touch isn't a program – Jim Jones Jul 22 '14 at 04:49
  • 3
    I just tried it both in `cmd` and `powershell` in Windows 7 without a problem. Then tried it again on the 8.1 machine of a colleague and can confirm that (the Cmdlet isn't present). You will have to search up the problem for that as this will bite you anyway with other things as well. In short: I'm sorry for you :/ – kaiser Aug 11 '14 at 16:55
  • 2
    fyi - Windows does not have a native touch command. The closest equivalent in Windows is "copy /b filename.ext +,," (where filename.ext is your file's name). The +,, is a special flag to copy telling it to simply update the date/time on the file. http://superuser.com/questions/10426/windows-equivalent-of-the-linux-command-touch – Gabe Halsmer Oct 07 '14 at 15:19
  • 8
    @SpencerKillen you need to use this command by using git bash. – Teoman shipahi Jan 08 '15 at 16:47
  • 2
    Works in command line if you specify the full path for touch ... C:\> "c:\program files (x86)\git\bin\touch.exe" .gitignore – War Jun 20 '15 at 16:40
  • 1
    worked for me in windows 10 64 bit machine from git bash – Yousuf Azad Aug 10 '16 at 14:10
  • 1
    Easiest way to get Git Bash is to install Github app, it will install Git Shell as well. – Izzy Helianthus Feb 16 '17 at 13:37
  • for folks who are coming from Mac, use what they have said above 'touch touch .gitignore'. Then, vi .gitignore. This will open up your editor. Then visit https://github.com/github/gitignore/blob/master/Unity.gitignore to get the ignore contents. Use Cmd + C to copy and Cmd + V on the editor open in your terminal and then :wq (save and quit) and you are good to go. – Jay May 29 '18 at 13:15
  • `Windows doesn’t have a native “touch” equivalent, which is a native Linux program that allows you to create empty files and change timestamps` – Legends Dec 03 '19 at 16:45
  • 1
    That's how it works, wondering why so many people are posting many different answers. – Alex Cio May 16 '21 at 11:55
  • 1
    Touch might be in this path instead - C:\Program Files\Git\usr\bin – PiggyMacPigPig Jan 06 '22 at 15:38
330

The easiest way to create the .gitignore file in Windows Explorer is to create a new file named .gitignore..

This will skip the validation of having a file extension, since it actually has an empty file extension.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chos
  • 3,431
  • 1
  • 12
  • 6
  • 12
    Definitely the easiest way, if you want to stay in pure Windows style. . . – Raj Jan 21 '14 at 04:59
  • 5
    This, is the best way for the laziest among us :D – JochemQuery Mar 18 '14 at 21:29
  • 6
    This worked great for me. Windows actually removed the last . so the file name was changed to just .gitignore when I saved the change. – JoBaxter Feb 23 '15 at 16:58
  • 4
    This is the real answer to what appears to be a bug in windows explorer... although I assume the original question is osx – Greg Woods May 08 '15 at 13:45
  • if you move your project to linux system for example it will keep the dot at the end of the file, for me this is not a good method, always stick with the standard naming conventions, everyone who asks how to make a `.gitignore` has the skill to open a text-editor and create a `.gitignore` file without extra risky hacks. – vdegenne Jan 12 '17 at 05:28
  • The question mentioned Xcode which run on OSX. This does not work on OSX. (There is no Windows Explorer on OSX.) – Noctis Mar 20 '17 at 09:27
  • Yes! This is the real answer. Let everybody vote this answer for others. – JM217 Nov 17 '19 at 06:52
  • Similar answer: [tanguy_k's answer](https://stackoverflow.com/questions/10744305/how-to-create-a-gitignore-file/26484621#26484621) – Peter Mortensen Jun 17 '22 at 18:06
214

The .gitignore file is not added to a repository by default. Use vi or your favorite text editor to create the .gitignore file then issue a git add .gitignore followed by git commit -m "message" .gitignore. The following commands will take care of it.

> .gitignore
git add .gitignore
git commit -m "message" .gitignore
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sully6768
  • 2,507
  • 1
  • 12
  • 12
  • 6
    Hi, thanx for your reply :), actually, i have created a .gitignore file, but when performing this command line: `git add .gitignore`, i got this message: `fatal: pathspec '.gitignore' did not match any files `, although, i make sure the .gitignore file does exist on my project folder, am i wrong ? – Luca May 24 '12 at 20:04
  • If git says the file doesn't exist - the file you've created has a different name. you can see all files in a folder with `ls -la`. Add to the question what you did (details) if you're still struggling – AD7six May 24 '12 at 20:28
  • My .gitignore file was existing already. I just added a rule to ignore eclipse.prefs and .log files Committed it. Will it start working immediately? – R11G Sep 12 '13 at 07:40
  • Very helpful. Also, this method works similarly with renaming folders/directories too (not just files). For instance `Z:\pristine-vagrant>ren "New folder" .ssh` – Daniel Dropik Feb 19 '14 at 04:41
  • In case of 'fatal: pathspec..' error, I simply ran git fetch then tried again git commit and push. It worked. – Santosh Kumar Arjunan Jun 11 '19 at 10:29
156

In Windows

  1. Open Notepad.
  2. Add the contents of your gitignore file.
  3. Click "Save as" and select "all files".
  4. Save as .gitignore

Easy peasy! No command line required!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
60

macOS and Linux one-liner

An easy way to get a default Git ignore without messing about with create/copy/paste is to use the curl command from the terminal. First cd into your projects root directory and then run the command by replacing MY_API_NAME with your API name from one of the following two sources:

gitignore.io

curl -o .gitignore https://www.toptal.com/developers/gitignore/api/MY_API_NAME

You can find your API name by searching from the list here and clicking Generate.

Java Example:

curl -o .gitignore https://www.toptal.com/developers/gitignore/api/java

GitHub

Alternatively, you can use the ones at GitHub. Find the filename for your API here.

curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/MY_API_NAME.gitignore

Java Example:

curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/master/Java.gitignore

Windows

Here are some similar alternatives for Windows.

But honestly setting that up looks like more trouble that it is worth. If I had Windows then I would just create an empty file called .gitignore in my project's root folder and then copy and paste the default text from gitignore.io or GitHub.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
  • Awesome! Just what I were looking for. I recommend ConEmu that is a window terminal that support curl. https://conemu.github.io/ – Morten Brudvik Apr 15 '21 at 13:51
58

On Windows, you can use cmd:

echo "" >.gitignore

Or use Git Bash cmd:

touch .gitignore,

This useful for a Linux and Mac system.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
seay
  • 599
  • 5
  • 8
  • echo > .gitignore works well. To continue to append the files to ignore, we can do echo "*.obj" >> .gitignore – ozkary Nov 13 '16 at 16:38
  • I would be careful about using this approach. On my computer, running Windows 10, using echo to create .gitignore resulted in a UTF 16LE formatted file, which Git apparently did not parse correctly. Creating the file through Windows Explorer resulted in an ANSI formatted file, which worked correctly with Git. – jlspublic Jun 19 '18 at 02:30
  • This one should be the accepted answer – Ashish Johnson Nov 19 '21 at 13:14
52

I want my contribution as well. This time, animated one :)

Vim (mini tutorial):

i   - start editing
ESC - get back to normal mode
:w  - save
:q  - quit

Enter image description here

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
45

Using the Git Bash console.

  • Navigate to your project
  • Type "touch .gitignore"

The .gitignore file will be created for you.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roberto Rodriguez
  • 3,179
  • 32
  • 31
35

My contribution is aimed at those on a Mac, and it can be applied to not only those working on an iOS project (as implied by the question mentioning Xcode), but any type of project.



The easy way that I do it is to go into the terminal and run vim .gitignore and then add the files. Usually you can just copy what you need from one of the templates on GitHub at https://github.com/github/gitignore.


Step 1
While in your project, type the following command

vim .gitignore

Enter image description here



Step 2
You now have your file open with Vim.

Enter image description here

Press i to insert text. You will see that the file is ready when you see the --INSERT-- at the bottom.

Enter image description here



Step 3 (option 1)
For Objective-C projects, you can copy from https://raw.githubusercontent.com/github/gitignore/master/Objective-C.gitignore and paste it into your .gitignore file:

Enter image description here

Press Esc, type in :wq, and press Return. Which saves the file.



Step 3 (option 2)
Add whatever files apply to your project.

If you are not sure what to add, the best keywords to use in your search engine would be to include your project type and text editor. For example, if you use Sublime Text you would want to add

*.sublime-workspace

And if you are working with a Cordova project in Dreamweaver you would want to add

_notes
dwsync.xml
JGallardo
  • 11,074
  • 10
  • 82
  • 96
32

Here a nice tip under Windows:

  • Right click in Windows Explorer, New > Text Document
  • Name it .gitignore. (with a trailing dot - that is the tip)
  • You end up with a .gitignore file :)

Tested under Windows 7 and 8.

This tip assumes that your Windows Explorer displays the file extensions.

Windows Explorer .gitignore

tanguy_k
  • 11,307
  • 6
  • 54
  • 58
18

Create a .gitignore file in include all files and directories that you don't want to commit.

Example:

#################
## Eclipse
#################

*.pydevproject
.project
.metadata
.gradle
bin/
tmp/
target/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anderson Lopes
  • 639
  • 7
  • 10
16

http://gitignore.io is an open source utility that can help you create useful .gitignore files for your project. There is also a command line API that you can access via a gi command: http://gitignore.io/cli

  1. Install gi command for OS X:

    $ echo "function gi() { curl http://gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile

  2. View .gitignore file contents (Output: http://gitignore.io/api/xcode,osx):

    $ gi xcode,osx

  3. You should see output on the terminal, if you want to append the results to a new .gitignore file.

    $ gi xcode,osx >> .gitignore

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joe
  • 1,320
  • 13
  • 11
16

I have another simple idea.

Let's use the echo command in cmd,

echo ./idea > .gitignore

This will create the .gitignore file having text content "./idea".

You may now manually change data from the file using a text editor.

Or simply

Console:

echo .gitignore notepad.exe

to instantly edit gitignore.

If you don’t know which files are should be gitignored for your IDE or operating system just go to www.gitignore.io.

gitignore.io - here it will generate the gitignore commands or text for you. Just say your API or OS. That’s it!. Just copy and paste into your file. Simple!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NIKHIL C M
  • 3,873
  • 2
  • 28
  • 35
15

You can go to Create Useful .gitignore Files For Your Project.

Select the IDE, operating systems or programming language. It will automatically generate one for you.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zohra Khan
  • 5,182
  • 4
  • 25
  • 34
14

Here's my personal favorite, http://help.github.com/ignore-files/

Also just in case you wanted to ignore Xcode files, refer to an answer to Git ignore file for Xcode projects.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sivakumar Kailasam
  • 452
  • 3
  • 6
  • 20
12

In Windows, open a DOS prompt (cmd) window, and use this command line:

type > .gitignore
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
caoglish
  • 1,343
  • 3
  • 19
  • 29
10

If you don't want to have your .gitignore file interfere with anyone else's repository, you can also use .git/info/exclude (see http://help.github.com/ignore-files/).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
EfForEffort
  • 55,816
  • 4
  • 36
  • 41
10

The following works in PowerShell and a command prompt (CMD):

echo '*.ignore_me' > .gitignore

I ran into a weird issue where Git effectively wouldn't read the .gitignore file. I then deleted the .gitignore file and created one using Vim which worked fine.

To add additional files to ignore, just call the following command:

echo 'another_file_to_ignore' >> .gitignore

It will append further files to the existing .gitignore file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MadJangi
  • 841
  • 8
  • 8
  • 2
    I had the same weird issue. Turns out to be the encoding, so be sure to save the file as utf-8. – aw04 Sep 16 '15 at 15:44
10

A few ways to create file .gitignore using cmd:

With the copy con command:

  1. open cmd and type cd to your Git repository

  2. Type copy con .gitignore and press Ctrl + Z.

    Enter image description here

With the start notepad .gitignore command

  1. Open cmd and type cd to your Git repository

  2. Type start notepad .gitignore and press the Yes button in the opened Notepad dialog box.

    Enter image description here

With the edit .gitignore command (Windows x86 only)

  1. Open cmd and type cd to your Git repository
  2. Type edit .gitignore and close the opened 'edit' editor.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
10

Windows

Enter image description here

File name: ".gitignore",
Save as type: All Files (.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ishan Lakshitha
  • 365
  • 3
  • 6
9

Do:

  1. Open a Git terminal
  2. Go to the Git repository of the project
  3. Create a .gitignore file by touch .gitignore command
  4. Use git add .gitignore command to add the ignore file
  5. Set ignore rules in the ignore file
  6. Run the command cat .gitignore

By running the command in step 3, you will get the .gitignore file in the project directory.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rashedul.Rubel
  • 3,446
  • 25
  • 36
9

You can directly create an empty .gitignore file. Open cmd in the location you need to add this file to, and type this command:

copy con .gitignore

Press Enter. We are now in edit mode of the newly created file, but we do not need to add anything now. Just press F6 and then press Enter.

Now you have an empty .gitignore file. Edit your file in whatever editor you have.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amado Saladino
  • 2,114
  • 23
  • 25
8
  1. To create a .gitignore file, you just create a .txt file and change the extension as in the following:

Enter image description here

Then you have to change the name, writing the following line on the cmd:

 rename git.txt .gitignore

where git.txt is the name of the file you've just created.

Then you can open the file and write all the files you don’t want to add on the repository. For example, mine looks like this:

# OS junk files
[Tt]humbs.db
*.DS_Store

# Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.pyc
*.xml
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

# Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*

# Project files
[Bb]uild/

# Subversion files
.svn

# Office Temp Files
~$*

Once you have this, you need to add it to your Git repository. You have to save the file where your repository is.

Then in your Git Bash, you have to write the following line:

Enter image description here

If the repository already exists, you have to do the following:

  1. git rm -r --cached .
  2. git add .
  3. git commit -m ".gitignore is now working"

If step 2 doesn’t work then you should write the whole route of the files that you would like to add.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SomeAnonymousPerson
  • 3,173
  • 1
  • 21
  • 22
8

Windows:

On the command line:

.>.gitignore

This will show an error, but it will work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Timar Ivo Batis
  • 1,861
  • 17
  • 21
  • What error will it show? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/53093031/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 17 '22 at 21:15
  • An explanation would be in order. E.g., what is the first dot in the command line for? [Standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin))? What does it mean? How does it work? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/53093031/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 17 '22 at 21:16
8

To add .gitignore file to your not application you can use the

> npx add-gitignore

Now you can type "node" and use user space bar to choose it and Enter. That will add the node .gitignore to the project.

enter image description here

Shinoy Babu
  • 1,641
  • 2
  • 12
  • 12
  • What do you mean by *"your not application"*? Please respond by [editing (changing) your question/answer](https://stackoverflow.com/posts/61169957/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 17 '22 at 21:31
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way***, *such as to provide screenshots of a user interface."*) and take the appropriate [action](https://stackoverflow.com/posts/66101455/edit) (it covers answers and terminal output as well). Thanks in advance. – Peter Mortensen Jun 17 '22 at 21:32
6

Without using the command line (on Windows)

  1. Open any texteditor (e.g. Notepad) and add your rules.
  2. Click menu FileSave As
  3. Save it as ".gitignore" (include the quotations)
YellowJ
  • 271
  • 5
  • 18
  • What text editor exactly? Do you mean "[Text Editor](https://help.ubuntu.com/community/gedit)" (repackaged [gedit](https://en.wikipedia.org/wiki/Gedit))? What platform (operating system and edition), incl. versions, was this tried on? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/34237832/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 17 '22 at 18:52
4

At work we are on Windows XP, and typing a period at the end of a filename doesn't work. A quick and easy way to create a .gitignore file without having the "You must type a filename"error is:

  1. open a cmd window and type "edit .gitignore".
  2. type "Alt (selects file menu), F, S. You now have an empty .gitignore file wherever your cmd prompt is pointing.

You can now populate it with your favorite text editor.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mario
  • 3,405
  • 6
  • 38
  • 48
4

To add any file in Xcode, go to the menu and navigate to menu FileNewFile...

For a .gitignore file choose OtherEmpty and click on Next. Type in the name (.gitignore) into the Save As field and click Create.

For files starting with a dot (".") a warning message will pop up, telling you that the file will be hidden. Just click on Use "." to proceed...

That's all.

To fill your brand new .gitignore you can find an example for ignoring Xcode file here: Git ignore file for Xcode projects

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Noctis
  • 190
  • 3
  • 7
4

If you use Sublime Text as your IDE, you can create a new file and save it as .gitignore. Simply using Ctrl + N for the new file, and Ctrl + S to save as ".gitignore".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mtpultz
  • 17,267
  • 22
  • 122
  • 201
4

You can type new-item .gitignore in Windows PowerShell.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
4

There is a pretty simple way to create a .gitignore file. This one is created on GitHub, and I'm pretty sure that most source controls offer the feature for creating a file there itself.

I am attaching an image-by-image tutorial for reference.

  1. Enter image description here

  2. Enter image description here

  3. Enter image description here

  4. Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Haseeb Mohamed
  • 1,459
  • 1
  • 11
  • 15
4

Have you see this article?

Easy to create .gitignore for the dotnet developers

It mentions:

Starting from .Net Core 3.0, you can take advantage of the build in the .Net framework gitignore file template just by typing dotnet new gitignore in your terminal.

I just tried it and this is the file it created:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Mono auto generated files
mono_crash.*

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Visual Studio 2017 auto generated files
Generated\ Files/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# Benchmark Results
BenchmarkDotNet.Artifacts/

# .NET
project.lock.json
project.fragment.lock.json
artifacts/

# Tye
.tye/

# ASP.NET Scaffolding
ScaffoldingReadMe.txt

# StyleCop
StyleCopReport.xml

# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# Visual Studio Trace Files
*.e2e

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json

# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info

# Visual Studio code coverage results
*.coverage
*.coveragexml

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/

# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets

# Microsoft Azure Build Output
csx/
*.build.csdef

# Microsoft Azure Emulator
ecf/
rcf/

# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/

# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs

# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak

# SQL Server files
*.mdf
*.ldf
*.ndf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl

# Microsoft Fakes
FakesAssemblies/

# GhostDoc plugin setting file
*.GhostDoc.xml

# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions

# Paket dependency manager
.paket/paket.exe
paket-files/

# FAKE - F# Make
.fake/

# CodeRush personal settings
.cr/personal

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Tabs Studio
*.tss

# Telerik's JustMock configuration file
*.jmconfig

# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs

# OpenCover UI analysis results
OpenCover/

# Azure Stream Analytics local run output
ASALocalRun/

# MSBuild Binary and Structured Log
*.binlog

# NVidia Nsight GPU debugger configuration file
*.nvuser

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Local History for Visual Studio
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd

##
## Visual studio for Mac
##


# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/

# Mac bundle stuff
*.dmg
*.app

# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# JetBrains Rider
.idea/
*.sln.iml

##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
3

On Mac -

you can just create a new text file.

Add content using https://www.gitignore.io/

Save the file with file format as - Rich Text document with attachments.

Change the file name to .gitingore and select use"." when a pop up comes as in the attached image.

Note: Since it is a hidden file, you won’t be able to see it in the directory. But it will be created.

See image

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jaspinder Kaur
  • 1,129
  • 11
  • 11
2

I use Notepad++. Use menu FileNew FileSave As.gitignore (Save as type: All types(.))

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Krishh
  • 4,111
  • 5
  • 42
  • 52
2

I realize this question is focused on how to "create" the gitignore file, but in case someone is interested in a quick way to add contents to the file once it is created, here is my answer using GitHub Desktop for those trying to "ignore" files that appear in their changes list.

  1. Make the changes to your code which generate unwanted changes in your repository.
  2. Go to GitHub Desktop and to your repository.
  3. Select all the changes and right click them.
  4. Add your changes to the gitignore file.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thor
  • 181
  • 1
  • 2
  • 8
1

Yes, Windows Explorer wouldn't allow you to create this file name. Another easy way to come around this is to create a dummy file in the directory, for example NewFile.txt, and then just simply rename it in Git Bash like the following:

mv NewFile.txt .gitignore
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zar
  • 11,361
  • 14
  • 96
  • 178
0

You can actually make Xcode generate it automatically, when you start a new project.

In order to do so, you'll have to start doing some harmless hacking yourself...

Before you begin: Make a backup of "Project Templates", as I predict you'll want to do more than I just mention, once you've discovered it.

Now, go to /Developer/Library/Xcode/Project Templates/Application/Cocoa Application/ Add your .gitignore file there.

That's all. When you create a new "Cocoa Application" project, then the .gitignore file is automatically copied from your project templates.

Beware: If you want to edit the templates themselves, use nano for that; do not use Xcode or TextEdit as they mess up the Unicode characters! Well, Xcode also messes up everything else.

Note: There's also a "File Templates", which you should also make a backup of before you start modifying them. Again: Use nano for editing them; not Xcode, nor TextEdit.

Here's one of my own .gitignore files, which you can use for inspiration:

.DS_Store
Icon\15
Icon\r
Icon\n
/*.xcodeproj/*.mode*
/*.xcodeproj/*.pbxuser
/*.xcodeproj/TemplateIcon.icns
/*.xcodeproj/.LSOverride
!/*.xcodeproj/default.*
/*.pbproj/*.mode*
/*.pbproj/*.pbxuser
/*.pbproj/*.perspective*
/build/
*.moved-aside
*~.nib
*~.xib

Note: I use Xcode 2.5 and Xcode 3.1.4 (I would prefer 3.1, but it keeps spamming my console)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

On Mac:

  • open terminal and run defaults write com.apple.finder AppleShowAllFiles YES anywhere.

  • restart Finder so you can see hidden files: command + option + escapeRelaunch

Then create a text file and you will be able to change the file extension to .gitignore.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lolelo
  • 698
  • 6
  • 18
0

In Ubuntu, you can create the .gitignore file and add (ignore) all the files over 50 MB from the current directory, ., using:

find . -size +100M | cat >> .gitignore
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mihai.Mehe
  • 448
  • 8
  • 13
0

I created this tool several years ago: https://github.com/czheo/gitignorepy

For example, you can easily create an .gitignore file for C++ by running

gg fetch c++ > .gitignore
czheo
  • 1,771
  • 2
  • 12
  • 22
-1

Here is a one-liner version of Linux "touch" in Windows

cd c:\<folder>\break
> .gitignore

That will create a blank .gitignore file where you can edit and add items to ignore.

cd C:\Users\test
dir .gitignore

Output:

 Volume in drive C is Windows
 Volume Serial Number is 9223-E93F

 Directory of C:\Users\test

18/04/2019  02:23 PM                 0 .gitignore
               1 File(s)              0 bytes
               0 Dir(s)  353,009,770,496 bytes free
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DonAriston
  • 101
  • 1
  • 5