Create new gitignore file on git bash
To create a new .gitignore
file in Git Bash, you can follow these steps:
- Open Git Bash and navigate to the root directory of your project using the
cd
command. - Run the command
touch.gitignore
to create a new file named.gitignore
. - Open the
.gitignore
file in a text editor using the commandcode.gitignore
(or your preferred text editor). - Add the files or directories you want to ignore to the
.gitignore
file, one per line. For example:node_modules/ *.log *.tmp
- Save the
.gitignore
file and close the text editor. - Run the command
git add.gitignore
to stage the new.gitignore
file. - Run the command
git commit -m "Added.gitignore file"
to commit the changes.
Alternatively, you can also create a .gitignore
file using the git init
command followed by git add
and git commit
commands.
Here's an example:
git init
echo "node_modules/" >>.gitignore
echo "*.log" >>.gitignore
echo "*.tmp" >>.gitignore
git add.
git commit -m "Added.gitignore file"
This will create a new .gitignore
file with the specified ignore patterns and commit the changes.