Table of contents
Git
It is a free and open source version control system that tracks changes in any set of computer files, mostly code for the collaborative development of software.
GitHub offers a cloud-based Git repository hosting service, another cloud-based service is gitlab.
About
It is a tool not a programming language.
It is a distributed and actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.
It makes collaboration easy. ie. separate branches for testing separate features, rollback changes on requirement etc.
Can be hosted remotely using Github, Gitlab etc.
Git Architecture
Staging Area: the staging area gives us space to prepare (stage) the changes that will be reflected on the next commit.
Upstream: generally refers to the original repo that we have forked.
Origin: is our own repo on GitHub, clone of the original repo of GitHub.
Some Basic Git commands
git init - to initialise an empty git repository.
git log - to explore the history of repository.
git status - displays status of working directory and staging area.
git add <filename> - to add a file(use . for all the files) to staging area.
git commit -m "" - to commit the changes into the local repository.
git restore --staged <filename> - to remove the file from the staging area.
git reset <reset_code> - all commits above this commit will be deleted.
git branch - to see all the branches.
git checkout <branchname> - to switch to this branch.
git merge <branchname> - to merge the branch to the current branch
git stash - to send the added files to the stash area.
git stash pop - to bring back all files from stash area.
git stash clear - to remove all files from the stash area.
git remote add upstream <link>- to add the upstream link (which can be used to fetch the recent changes)
git remote -v -to see all the remote links attached to the repository.
git fetch - it fetches from origin (our fork).
git fetch upstream - it downloads changes from the original repository from where we forked it and we need to merge it manually.
git merge upstream/<branch_name> - to merge the changes done in remote repository to the local repository.
git pull upstream/<branch_name> - it downloads changes from the original repository and merges it into the current repository.
For all the git commands visit the git documentation here.