Git: Commit (and ignore files from commit)

jgunawancode

Johan G

Posted on May 11, 2022

Git: Commit (and ignore files from commit)

The Basic Git Commit Workflow

  1. Make Changes
  2. Add Changes
  3. Commit

1. Make Changes

Make new files, edit files, delete files, etc. in a location that is tracked by Git.

2. Add Changes

Group specific changes together, in preparation of committing. The changes added in this step are not committed yet to the repo. Consider this step as a Staging step/area.
git add [file1] [file2]
Explicitly add the files to be added.
git add .
Stage ALL changes at once.

3. Commit

Commit everything that was previously added.
git commit -m "Describe the commit here"
The -m flag is to pass an inline commit message. Without this flag, a text editor will be launched to give a commit message.

Ignoring Files

There are some files that should not be committed such as:

  • Temporary files, build results, and files generated by an IDE
  • Secrets, API keys, credentials, etc.
  • Log files
  • Dependencies & packages

To ignore those files create .gitignore file in the root of a repo. Inside the file, write patterns to tell git which files & folders to ignore.

See this example of ignoring files generated by Visual Studio.

💖 đŸ’Ș 🙅 đŸš©
jgunawancode
Johan G

Posted on May 11, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related