Git- add (stage), commit and unstage changes

Before this if you want to see Git workflow/ three tree architecture

Stage changed files
To add the changes to the staging index from working directory use following command-

 git add .

This will stage all changed files (.) in working directory
To add specific file to staging index-

 git add filename.txt

Stage and commit at once

Per above this is 2 stage process to commit changes to repository. If you have all files that are ONLY modified use following command to directly commit from working repository. This command can also be used for renamed file.

 git commit -am "provide a message here"

So no need to explicitly add to the staging index, instead the above command shall update repository.

Commit changes

Going back to committing changes, use following command-

 git commit -m "message goes here"

Please note the best practice to put the message on what is this commit about and the message to be in the present tense.

Unstage changes

 git reset HEAD fiel.txt

If you put something in staging directory and don’t want there, then use reset head.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s