What is Git?
Git is a version control system which is used to track changes in the computer files. It's mainly used for the source code management (SCM).
What is version control system?
Version control, also known as source control, is the practice of tracking and managing changes to software code. And Version Control System is a system which helps in the accomplishment of the Version Control.
We're not diving into details of the version control system.
Git Is a Distributed Version Control System which allows you pull (copy the complete code from directory) and push (Push your code into repository), create branches in the alongside main repository where you can work without disturbing the main repository and merge the code whenever required.
It saves you when the everything goes sideways, it can revert back the code to its previous version or commit.
I have given a table below which can be used as a cheat-sheet and you can take screen-shot of it as well for the future use.
Commands | Functions |
git config --global user.name "name" | Sets the name you want attached to your commit transactions |
git config --global user.email "email address" | Sets the email you want attached to your commit transactions |
git init {project-name} | Creates a new local repository with the specified name |
git clone {url} | Downloads a project and its entire version history |
git status | Lists all new or modified files to be committed |
git add {file} | Add {file} into GIT tracking for commit |
git reset {file} | Unstages the file, but preserves its contents |
git commit –m « meaningful commit message » | Records changes permanently in version history |
git branch | Lists all local branches in the current repository |
git branch {branch-name} | Creates a new branch |
git checkout {branch-name} | Switches to the specified branch and updates working directory |
git merge {branch-name} | Combines the specified branch’s history into the current branch |
git branch -d {branch-name} | Deletes the specified branch |
git reset {commit} | Undoes all commits after {commit}, preserving changes locally |
git reset --hard {commit} | Discards all history and changes back to the specified commit |
git fetch {remote} | Downloads all history from the remote repository |
git merge {remote}/{branch} | Combines the remote branch into the current local branch |
git push {remote} {branch} | Uploads all local branch commits to GitHub |
git pull | Downloads bookmark history and incorporates changes |