Being a software developer having a good knowledge about GIT is important
So lets learn the basics of git using a simple and small project.Before diving into the project lets learn what is git and github
GIT
Git is a version control system that lets you manage and keep track of
your source code history
GITHUB
Github is a platform that lets you and others work together
on projects from anywhere
Now lets start open (cmd/terminal) and type : cd Desktop
-> Create a folder git-project
$ mkdir git-project
-> move to project folder
$ cd git-project
-> Initialize git using follwing command. It creates .git subdirectory which contains necessary git info (ie , commits , history) of the repository
$ git init
-> create a text file in it hello.txt and enter some data (" I love programming") in it
$ echo "I love programming" > hello.txt // For linux users
-> we have a created a project and made some changes to it by creating a file and data. But how git knows we need add the changes to the staging area and commit.
-> These two commands are the most frequetly used commands
$ git add hello.txt // add the changes to the staging area
$ git commit -m "initial commit" //it saves all the changes
Hurray our project is completed !!!! 🥳🥳🥳
-> Few days later . You learned a new language "c++". (a new feature to our project) -> so you have added the text in the hello.txt "I learned c++" .
-> Then you modify the file and add it to the staging area and commit the changes.
$ git add hello.txt // add the changes to the staging area
$ git commit -m "learned c plus plus" //it saves all the changes
So now our project has two versions.
-> One is the which you add the text "I love programming" and
-> Other is which you added "I learned c++" to the same file
following command gives all the commit you have made.
$ git log --\\gives commit id and comment
Later you realised that the second version is not good and decided to go back to first version. you can simply you go to first version using commit id.
$ git checkout commitid //example git checkout d48f99c
Later you can switch back to second version again. This is what Version control means. In the absence of git we would have created each copy of our project in seperate folders but git made it efficient. Hope you enjoyed it 😊