Git Cheatsheet

What is Git?

Taapas Agrawal
Jun 22, 2018 · 6 min read
  • To display current saved configration type git config --list
  • Open this using text editor and add names of files you want to ignore
  • For adding all files at once use –git add -A
  • To remove files from staging area use –git reset <filename>and to remove all simply type git reset
Staging and committing Flowchart.
  • To check status of the cloned repository use git remote -v This will give the location from where it is fetched.
  • git branch -a gives all the branches in the cloned repository.
  • Add the file to the staging area using git add -A.
  • Commit these files with appropriate message .
  • Now before pushing it back . We need to pull and check whether any other person made a change in the branch since the last time type in git pull origin master ( If on master branch else use branch name in place of master).
Basic process Flowchart.
A typical image which represents blue dots as master and rest as side branches.
  • To check all the branches present use git branch
  • To switch over branch use git checkout <branchname>
  • To push a commited changes type in git push -u origin <branchname>
  • To merge the current branch you are working on to master use git merge <branchname>
  • To push the changes we simply use git push origin master
  • To check it they are merged type in git branch --merged
  • If the branch is successfully merged we can now delete the branch–git branch -d <branchname>
  • Then it will modify your working tree and the index (“staging area”) according to the <mode> selected.
  • The mode must be one of the following (If <mode> is left blank then by default --mixed is selected) —
  • --soft —Does not touch the index file or the working tree at all (but resets the head to <SOME-COMMIT>, just like all modes do). This leaves all your changed files “Changes to be committed”, as git status would put it.
  • --mixed — Resets the index but not the working tree (i.e. the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
  • --hard — Resets the index and working tree. Any changes to tracked files in the working tree since <SOME-COMMIT> are discarded.
  • To display the stash stack use git stash list .The list will be numbered as stash@{0},stash@{1} ….stash@{n} .
  • Finally when you decide to work again and want to apply the changes use git stash apply . To apply any older stash from the stash stack use git stash apply stash@{n} where n is the stash number.

Kharagpur Open Source Society

We are a group of Open Source Enthusiasts who focus on something more preliminary and relevant, "A Love for Coding".

Taapas Agrawal

Written by

Undergraduate IIT Kharagpur

Kharagpur Open Source Society

We are a group of Open Source Enthusiasts who focus on something more preliminary and relevant, "A Love for Coding".