Git for Beginners.
In this article or blog we are going to know about git and some part of github as beginners level.
Git
In simple words git is a open-source and version control system that track the changes of your code into your local system and save it inside the .git folder so the developer can see the changes of the code and track it.
Github
On the other hand github is web-based platform where developer manage their repositories and code online. Github Provides GUI (Graphical User Interface) so user or developer can understand easily.
Some basic aspects of git
- What is Repository?
The repository is the project folder which contain the .git folder (hidden folder). Now here, is the main part how the .git folder is created ? In some online documentation have a line ‘git repository is a .git folder ’ but it is not true. The repository contains project folder and the .git folder both, even the git makes the project folder to repository so the question is What is .git folder and how does it create ?
So, when we run the “git init” or “git clone” command so the .git folder is created in project folder. This folder contains all the history of project , commits, head, branch, config files means all the project data.
2. What is Branch ?
Branch is main part of git. it is core and important concept to understand the git. Git branch create with “git branch <branch_name>” but the main magic is In a single repository we can Create Multiple branch and inside “.git/refs/heads” file we can see the branch name in a file format. Each file store their latest commit.
Git uses by default ‘main or master’ branch so when we clone the project also that time git use main branch although all branch are comes while cloning the project but git use main or master branch we can switch the branch with “git switch <branch_name>” command to use a particular branch code.
3. What are heads and commit ?
HEAD file holds the current branch reference like “refs/heads/<current_branch>”. some times it’s directly point to commit but not by default when head has been set then it shows the commit instead of reference.
Commit is a snapshot of your project at a specific point of time. it create unique id for every commit and developer write a message for every commit so developer can track the commits. if need the previous code so simply achieve with ‘git revert <commit_id>’ command. This command generate the new commit and undo the specific commit changes.
We can not directly run git commit command. We need to run first “git add <file_name>” for specific file , for all “git add .” to this command file move to staging area (simply lobby) then it ready for commit with “git commit -m message”. git folder save the commits in “.git/objects” folder. There is one interesting thing every commit store reference of it’s parent so we can find any commit through child to parent go ahead until find the destination.