New Git Repository Setup:

Basically, the directory is called Repoitory or ‘Repo’ for short. Now if you want to start Git on any of your projects, first you have to go to the project directory from your Git Bash or your CMD command line. Or if you right click inside your project, you will see an option called Git Bash Here. This will open the git bash with the path of this directory by clicking from inside your desired project directory and you can now type any git command for the directory.

Now suppose you have a directory called git-learn in C: xampp htdocs. And there are some files inside. Now here if you want to start Git. Then you have to type the following command.

git init

Now since we want to track everything inside the git-learn directory, so I run the git init command from inside the git-learn directory. And that’s where Git’s repo setup became inside this directory. Now Git can start tracking all of your repo or directories, all the files or folders inside this directory. However, even if tracked, Git will not store them as versions. For that you have to specifically tell which one exactly when and how to save.

Save a specific file of repository or all files as git version:

Before saving a specific file or repository of repository as git version you first need to understand how git works?

When we make changes to the local repository while working on Git, we are in the working directory. And then after giving the git add command, it goes to the staging area and after giving the git commit command, it is permanently added to the local repository. If you want later, it can be uploaded to the remote (GitHub, gitLab, bitbucket) repository with git push command. Notice the image below:

Check the current status of the git

We now want to see the current status of our Git, i.e. which files are not tracked or which files are in staging. That is why we will use the following command:

1
git status

Notice that I have two files in this directory named test.php and index.php. Since I just initiated Git in this project, both files are un-tracked here. And also gives some hints on how to track the files.

Taking File Staging Area

Suppose we first want to track our test.php file, that is, we want to take the test.php file to the staging area. That is why we have to give the following command:

1
git add test.php

The track.php that I have tracked shows it in the Changes to be committed section. And below is the previous un-tracked file. However, at the moment we have the test.php file in the staging area, so if you commit now, Git will only keep this file in the version history. And index.php file that has not been tracked will not do anything about it. Now if we want to give a command to track all the un-tracked files inside this directory then the git command will be as follows:

1
git add --all

or

1
git add .

Now if you give the git status command, you will see that all the tracks are done, which means they are all in the staging area. No files un-tracked. The previous test.php is still in the staging, since we haven’t committed it yet. Now with index.php file and moving to staging area. If you commit now, Git will keep a complete version of the two together.

commit:

commit means final. That means you will make the final decision whether to keep your tracked changes in Git Repo? If you think Git Repo will do, you have to commit. And if you want to commit, you have to give a message with each commit so that you can understand at any time later on which committee was done for what reason. Everything will be in one line like this:

1
git commit -m "New Message Added"

Here New Message Added is the message of our committee.

Note: You cannot commit any file or directory before taking it to the staging area.

Modify the file and re-committed

Now we have a version. But we have a lot more work to do on the project. Now I will add some new variables to the test.php file. The file is currently in the same condition as the new variable and its values

1
2
3
4
<?php
$students=["Safan","Shail","Tortoiz"];
echo "Hello This is my First Git Learn";
?>

Now if you save the test.php file and check the git status, you will see that the file shows it in a modified and un-tracked state.

Now I want to take this un-track file on stage and make a final comment

1
git add --all

And for the Final Commit:

1
git commit -m "New Variable $students Added"

Leave a Reply

Your email address will not be published. Required fields are marked *