Git

Git Commands

  1. git –version
  2. git config –list
  3. git config –global user.name “Hello World”
  4. git config –global user.emao “hello@world.com”

  1. clear
  2. git config user.email
  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

  • REVERTING THE CHANGES
    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:


Logs

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


Branching

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
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