Command Line
To run gitignore.io from your command line you need an active internet connection and an environment function. You need to add a function to your environment that lets you access the gitignore.io API.

Git

Bash

1
git config --global alias.ignore \
2
'!gi() { curl -sL https://www.toptal.com/developers/gitignore/api/[email protected] ;}; gi'
Copied!

Linux

Bash

1
echo "function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/\[email protected] ;}" >> \
2
~/.bashrc && source ~/.bashrc
Copied!

Zsh

1
echo "function gi() { curl -sLw "\n" https://www.toptal.com/developers/gitignore/api/\[email protected] ;}" >> \
2
~/.zshrc && source ~/.zshrc
Copied!

Fish

1
printf "function gi\n\tcurl -sL https://www.toptal.com/developers/gitignore/api/\$argv\nend\n" > \
2
~/.config/fish/functions/gi.fish
Copied!

macOS

Bash

1
echo "function gi() { curl -sL https://www.toptal.com/developers/gitignore/api/\[email protected] ;}" >> \
2
~/.bash_profile && source ~/.bash_profile
Copied!

Zsh

1
echo "function gi() { curl -sLw "\n" https://www.toptal.com/developers/gitignore/api/\[email protected] ;}" >> \
2
~/.zshrc && source ~/.zshrc
Copied!

Fish

1
printf "function gi\n\tcurl -sL https://www.toptal.com/developers/gitignore/api/\$argv\nend\n" > \
2
~/.config/fish/functions/gi.fish
Copied!

Windows

Paste the following scripts inside your PowerShell profile (run $profile inside PowerShell to get the profile's location path).

PowerShell v3 Script

1
#For PowerShell v3
2
Function gig {
3
param(
4
[Parameter(Mandatory=$true)]
5
[string[]]$list
6
)
7
$params = ($list | ForEach-Object { [uri]::EscapeDataString($_) }) -join ","
8
Invoke-WebRequest -Uri "https://www.toptal.com/developers/gitignore/api/$params" | select -ExpandProperty content | Out-File -FilePath $(Join-Path -path $pwd -ChildPath ".gitignore") -Encoding ascii
9
}
Copied!

PowerShell v2 Script

1
#For PowerShell v2
2
Function gig {
3
param(
4
[Parameter(Mandatory=$true)]
5
[string[]]$list
6
)
7
$params = ($list | ForEach-Object { [uri]::EscapeDataString($_) }) -join ","
8
$wc = New-Object System.Net.WebClient
9
$wc.Headers["User-Agent"] = "PowerShell/" + $PSVersionTable["PSVersion"].ToString()
10
$wc.DownloadFile("https://www.toptal.com/developers/gitignore/api/$params", "$PWD\.gitignore")
11
}
Copied!
Create a Command Line Prompt Script If you have installed msysgit), create gi.cmd with content below. And copy it to C:\Program Files\Git\cmd\gi.cmd, assuming msysgit was installed to c:\Program Files\Git. Make sure that C:\Program Files\Git\cmd is added to the environment variable path.
1
@rem Do not use "echo off" to not affect any child calls.
2
@setlocal
3
4
@rem Get the abolute path to the parent directory, which is assumed to be the
5
@rem Git installation root.
6
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
7
@for /F "delims=" %%I in ("%~dp0..") do @set git_mingw_root=%%~fI\mingw
8
@if not exist "%git_mingw_root%" @set git_mingw_root=%git_install_root%\mingw64
9
@set PATH=%git_install_root%\bin;%git_mingw_root%\bin;%PATH%
10
11
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
12
@if not exist "%HOME%" @set HOME=%USERPROFILE%
13
14
@curl.exe -L -s https://www.toptal.com/developers/gitignore/api/%*
Copied!
Last modified 11mo ago
Copy link