Git Commands
- git symbolic-ref HEAD
- git log –oneline –graph –decorate –all
- git –version
- git config –list
- git config –global user.name “Hello World”
- git config –global user.emao “hello@world.com”
- clear
- git config user.email
- git help
- git help commit
Linux Commands
- pwd
- cd ~
- cd ..
- ls
- ls -l
- ls -lrth
- cd folder
Git Basic Commands
- git init
- ls -la
- git status
- git add filename.ext
- git add .
- git commit -m “Take snapshot till this point”
- git commit -am “add and commit at the same time”
- git log
- git log –author=”Hello World”
- git log –oneline
- working copy >> staging area >> repository
- git diff
- git diff filename.ext
- git diff –staged
- git rm filename.ext
Rename file
Way 1
- git add newfilename.ext
- git rm oldfilename.ext
Way 2
- git mv oldfilename.ext newfilename.ext
Undo changes in file (copy repo file to local file)
- git checkout — filename.ext
- 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
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
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
OR
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