- Git
- Why Use Git?
- Github
- Why Use Github?
- Workflow On Git
- Branching Merging And Conflicts
- Basic Git Commands
- Useful Hints
Git
Git is a version control system i.e software that is used for tracking the changes in any set of files over time so that we can go through the specific versions later. It is usually used for coordinating work among the programmers and collaboratively developing source codes during software development. It was created by Linus Torvalds in 2005. Git is open-source software distributed under GNU General Public License.
Why Use Git?
- Go to the earlier version when needed
- One can undo mistakes
- Things don't mix up since it provides the feature of branching
- Distributed development i.e. multiple persons can work
- Community Support, since there are more than 40 million users over the globe so we can easily get help when getting stuck
Github
Github is an online platform that provides hosting services to the git repositories. Suppose a team is working on a project, then to collaborate on a git-enabled repository, they need to keep a copy of the project at a central place so that anyone can access it. Such a central platform is called the host and Github is a host. Hence, Git is a tool and Github is a service.
Why Use Github?
- It acts as a central platform so that one can access the files easily
- Github also act as a backup for our files, in case our machine gets destroyed.
Workflow In Git
There are three stages or areas in Git which are as follows:
- Working Area
- Staging Area
- Committed Area
Working Area:
It is also known as an untracked area i.e. files are not tracked in this area. Here we can create files, update them as well as delete them.
Staging Area:
It is also known as the index stage. It is the preparation area before we add the changes to the committed area. From this area, the tracking of the files is started. Although, we can still make the changes to the files, and if we do so we will go back to the untracked changes.
Commited Area:
We make a commit with a message that tells what changes we had made in the files. We are committing, it means that we are making a version or a checkpoint i.e. we can access it in the future even after the next commit.
Branching, Merging, And Conflicts
Branching:
Branches are used to develop features isolated from each other. The default branch is the "master" branch whenever we create a repository. Other branches can be made whenever needed.
Merging:
We use other branches for making any changes and add them back to master upon completion. The process of adding the new modified branch to the master branch is called merging.
Conflicts And Resolving Them:
After passing the commands to merge, git tries to auto-merge the changes. Unfortunately, this is not always possible and sometimes results in conflicts. We are responsible to merge those conflicts manually by editing the files shown by Git. After changing we need to mark them as merged.
Before merging the files we should preview them.
Basic Git Commands
git --version
= To check whether git is installed, if installed then it tells its versionmkdir <FolfderName>
= To make a repository on local machinetouch <FileName>
= To add a file in the repositorygit init
= To initializing the Git repositorygit add <FileName>
= To add particular file to the staging areagit add .
= To add the whole folder to the staging areagit rm -cached <FileName>
= To remove file from the staging areagit commit -m "Message"
= To add changes in the committed area with a messagegit commit -am "Message"
= To add files from the working tree to the committed area directly with a messagegit status
= To check the status of a repositorygit log
= To check the commit historygit checkout <CommitHash>
= To go back in a state of working tree in a particular commitgit restore --staged <FileName>
= To move a file from the staging area to the working areagit branch <BrabchName>
=To create a new branchgit checkout <BranchName>
=To switches to an named branchgit merge <BranchName>
=To merge the named branch in the current branchgit branch -d <BranchName>
=To delete the named branchgit checkout -b <BranchName>
= To create and switch to the named branchgit clone <URL>
= To clone remote repository to local machinegit pull
= To update your local repository to the newest commitgit push origin master
= To move files to the master remote repository on the Githubgit push origin <BranchName>
=To move files to the branch remote repository on the Githubgit checkout -b hotfix-<BranchName>
= To create an temporary repositorygit diff <SourceBranch> <TargetBranch>
= To preview files before merging
Useful Hints
gitk
= Built-in git GUIgit config color.ui true
= To use colourful git outputgit config format.pretty oneline
= Show log on just one line per commitgit add-i
= Use interactive addinggit log --help
= To get helpgit log --name-status
= To see only those files which have changedgit log --graph --oneline --decorate --all
= If we wanna see an ASCII art tree of all the branches, decorated with the names of tags and branches
Images taken from Google.
Your suggestions and feedbacks are appreciated.
You can write back to me on:
abhishek.990914@gmail.com