Kaigai Blog living abroad in my twenties

【My Study Note】Add and Commit

Infotech Web Developer

Add and Commit


Before you add any files or make any changes, it’s always good practice to check if any changes or commits are currently there. You can do this by using the git status command.

git status
on branch main
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Git status also displays what branch you’re on. In this instance, I’m prompted that I’m on the branch called main and that my branch is up to date with the origin main.

This means that all the latest files on my local machine are exactly the same as what is displayed on the GitHub UI, which represents the server to that everyone commits to.

Git status also tells me that I have nothing to commit and that my working tree is clean.

How to add a simple text file

I’ll add a file called test.txt by using the command touch test.txt. Then I’ll run the command git status again.

touch test.txt
git status

Now git would tell me that I have an untracked file which is the test.txt file that I just added.

It would also tell me that I have nothing added to the commit but that untracked files are present and that I should use git add to track them.

Git Add

The purpose of the git add command is that you’re essentially prompting git and letting it know that you want to track this file and that it will be included as part of your commit.

Unstaging the file from the commit

git restore --stage test.txt
Git Addの状態から元に戻す

The staged area is really important because you’re essentially preparing to get all of the files and changes that you want as part of whatever feature you’re working on.

Basically, you are getting all of that content ready for commit. You also have to remember that this is only on your local machine. The distributed manner of git means it will only push to the server using the actual push command itself.

But any change you make here is only specific to you and your local machine. Anyone else who pulls down the project from GitHub will only get what’s available on the remote server.

How to commit command

git commit -m "Adding a new file for testing"

However, note that all of these changes are on your local machine, and they will only be uploaded to the remote server when you run the push command.

この状況では、自分のパソコン内でアップロードしているだけで、サーバーにアップロードしているわけではない