Git Commands

  1. git symbolic-ref HEAD
  2. git log –oneline –graph –decorate –all
  3. git –version
  4. git config –list
  5. git config –global “Hello World”
  6. git config –global user.emao “”

  1. clear
  2. git config
  3. git help
  4. git help commit

Linux Commands

  1. pwd
  2. cd ~
  3. cd ..
  4. ls
  5. ls -l
  6. ls -lrth
  7. cd folder

Git Basic Commands

  1. git init
  2. ls -la
  3. git status
  4. git add filename.ext
  5. git add .
  6. git commit -m “Take snapshot till this point”
  7. git commit -am “add and commit at the same time”
  8. git log
  9. git log –author=”Hello World”
  10. git log –oneline

  • working copy >> staging area >> repository

  1. git diff
  2. git diff filename.ext
  3. git diff –staged

  1. git rm filename.ext

Rename file

Way 1

  1. git add newfilename.ext
  2. git rm oldfilename.ext

Way 2

  1. git mv oldfilename.ext newfilename.ext

Undo changes in file (copy repo file to local file)

  1. git checkout — filename.ext
  2. git reset HEAD filename.ext

    git checkout versionnumber(few chars) — filename.ext
  • Pull Request
  • Watch
  • Star
  • Fork
  • Github issues and Labels
  • Github Wiki
  • Git Organization

Useful git commands for production:


git log –oneline
To display commit log in one line format

git diff-tree --no-commit-id --name-only -r <commit_id> git show --pretty="" --name-only <commit_id> git ls-tree --name-only -r <commit_id>
git show --name-only <sha> git show --stat --oneline HEAD


git branch
To show all existing branches on local machine

git checkout -b NewBranch
To create new branch from master branch

git checkout Branch
To switch from current branch to specified branch

git branch -d BranchName
To delete specific branch

git push origin :branchname
git push origin –delete :branchname
To delete remote branch

Merging Changes from Another Branch to Current Branch

git checkout target-branch
Switch to target branch e.g. master or dev

git merge source-branch
Merge change from source-branch to current branch e.g. git merge CHG001

Revert Uncommit Changes

git checkout — file
To revert all uncommitted changes for specified file

git checkout — .
To revert all uncommitted changes for all files

Revert Commited Changes

git revert [-n] hashcommitcode
To revert commited changes for hashcode

Reset Pushed Changes

git reset –hard hashcommitid
To reset till specified hashcommitcode

Push after reset

git push -f origin master
To push changes forcefully to git repository