How to configure Git for the first time?
When you are using it for the first time, you have to set your username and email in the configuration file. it’s very easy to configure this. Just follow these steps below:
$ git config --global user.name "john.doe"
$ git config --global user.email "john@doe.com"
There are many other configuration options. You can check those here.
How to initialize Git?
You use this to build a version-control system for your project. To use this, first, you have to initialize it in your project folder. It creates a hidden folder to keep track of your changes. Just do this and it’s done:
$ git init
If you want to know more, click here.
How to stage files in Git?
As discussed earlier, the staging area is the place where we put our files after reviewing that are ready to be committed. When you add new files to your repository, they are marked as Untracked. To get it to track them you need to stage the files.
To add a single file in the staging area:
$ git add <filename with extension>
You can also stage all files in our project folder in one go:
$ git add .
OR
$ git add --all
OR
$ git add -A
Want to master this? Check out this.
How to commit changes in Git?
Making a commit is like creating a “Checkpoint” in your project. When you make a commit, it saves a screenshot of the current state of the project. We add commits to keep track of our progress and changes as we go on.
We have to add a message when we commit. This is for your own understanding purpose. It helps you to find what was the main motive of this commit.
$ git commit -m "<Enter your message here>"
There are many other options that can be added with commit. A complete guide can be found here.
How to commit without Staging?
Yes. You can commit without adding files to the staging area. Actually, the thing is you can merge these two steps into one. Don’t follow this approach always as this will commit all the files in your directory. There can be some files that are not supposed to be committed. When changes are very less, you can use this approach.
$ git commit -a -m "<Enter your message here>"