WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 7 of 100

What is the difference between ’git add’ and ’git commit’ commands?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, the git add and git commit commands are two separate commands that serve different purposes in the version control process.

git add is used to add changes made to files in the working directory to the staging area. The staging area is a temporary area where you can prepare your changes before committing them to the repository. When you run the git add command, Git will take a snapshot of the changes you’ve made to the files in the working directory and add them to the staging area.

Here’s an example of how to use the git add command:

    # Add all changes in the working directory to the staging area
    git add .

# Add specific files to the staging area git add file1.txt file2.html

git commit, on the other hand, is used to create a new commit with the changes that you’ve added to the staging area. A commit is a permanent snapshot of the changes made to the files in the repository. When you run the git commit command, Git will create a new commit with the changes you’ve added to the staging area, along with a commit message describing the changes.

Here’s an example of how to use the git commit command:

    # Create a new commit with the changes in the staging area
    git commit -m "Add new feature to web application"

In summary, the git add command is used to add changes to the staging area, while the git commit command is used to create a new commit with the changes that have been added to the staging area. By using these two commands together, you can effectively manage changes to your codebase and keep track of the history of your project.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics