GIT
So now you guys thinking of what is git? right . don’t worry i am here to explain that.
If you are fresher like me then this post is for You!.
Now let’s understand with a small example you want to create a website so there will be a fronted and backend codes. And you and your friend are working on it. Now you will save the code in your PC and your friend will save the work in his PC now if any error occurred in your code and you asked your friend for help now he has to send the entire folder how can he send you he cant send it through mails assume that he is far away from your home town. So to help with we have a great feature called (SCM) source code management System in GIT. Now you can daily upload your work to git and it will organize that and your friend can pull the codes from git and work on it and re upload it .So i think now you got a idea on what is GIT ?.
Another Extraordinary feature in git is (VCS) version control System . Now lets understand with a example suppose we released a app with V1.0 and later we found some bugs and we want to add some extra features to it and we created as V2.0 , Git tracks every little change we do in files. Now we want to update the code in order to release new version now we can use all the V2.0 code to create new version and you think that new code you created and saved contains errors you can easily switch to older version.
Now we will understand the workflow of git mainly there are 4 main components in git local repository, index or staging area working area and central repository.
Let’s understand them quickly working area is where we develop the code and make modifications and next staging area is where code will wait until it is ordered to go to local repository
Local repository is where we keep final files and files which are ready to upload to remote central repository all files in the local repository are tracked by git that means if you change a single line in the code in working area it will show a error that you need to again push the file to local repository
Next the main one is remote repository or central repository where our all codes are managed assume it like a cloud where all our codes are stored along with version control system.
Now lets see some of the basic commands we use in git
- “git init” . The git init command is the first command that you will run on Git. The git init command is used to create a new blank repository. It is used to make an existing project as a Git project.
- “git add” .The git add command adds a file to the Git staging area. This area contains a list of all the files you have recently changed before committing the file the will be in ready state in staging area.
- “git commit” .The git commit command “captures a snapshot of the project’s currently staged changes”. Committed snapshots can be thought of as safe versions of a project Git will never change them unless you explicitly ask it to.
- “git push” .The git push command is used to “upload local repository content to a remote repository”. Pushing is how you transfer commits from your local repository to a remote repo.
- “git pull” .The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.
- “git clone” .If a project has already been set up in a central repository, the git clone command is the most common way for users to obtain a development copy.
- “git branch” .Suppose we are creating a web page now you have 2 ideas to implement now you want to see which one is good to see .In this case we will create a branch we will have all the commits in branch also but after we checkout to branch we separately and at last when we feel it is was good we can merge the sub branch to master and commit the changes.
8. “git checkout” .The git checkout command is used to switch between branches in a repository.
9. “git merge” .To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.
10. “git revert” .The git revert command is used for undoing changes to a repository’s commit history. Other ‘undo’ commands like, git checkout and git reset.
11.”git reset” .To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified.
12 .“git log” .The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit , the message associated with each commit.
GIT life cycle: