Some common and advance useful GIT command
$ git clone RepositoryAddress
Ex.
$ git clone https://github.com/arif2009/AspMvcPractice.git
# If it prints a file path, look at the contents of that file for further information. That files also ignored
$ git config core.excludesfile
$ echo # ASDf >> README.md
$ git init
$ git add README.md # . for all
$ git commit -m "Initial commit"
$ git remote add origin https://github.com/arif2009/GIT-HELP-GUIDE.git
$ git push -u origin master
# To show the origin
$ git remote -v
# To change the origin
$ git remote set-url origin git@github.com:arif2009/OnlineRegistrationSystem.git
-> press q
#OR
$ clear
$ git log
$ git reflog # Show the current branch history
$ git reset --hard master@{"10 minutes ago"}
$ git reset --hard master@{1}
$ git reset --hard master@{14:30}
$ git log --oneline
$ git show # Show the last commit
$ gitk # Show the log of all user changes
$ git diff # show the local changes
$ git log --graph or gitk. # Both also accept --all, which will show all the branches instead of just the current one.
$ git log --all --grep='company name must be bigger' # Search the commit log (across all branches) for the given text.
$ git shortlog -s -n
$ gitk --follow [filename] # --follow : Continue listing the history of a file beyond renames (works only for a single file).
$ git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n # List Remote Git Branches By Author
$ history # https://stackoverflow.com/a/14417188
$ git status
$ git pull
$ pull origin master
$ git pull origin master --allow-unrelated-histories # If you change git origin
# Note: $ git pull = $ git fetch + $ git merge
$ git add fiename
$ git commit -m "Message" # -a for all
$ git push origin BranchNameToPush
$ git push origin NewBranch
# Combines the specified branch’s history into the current branch
$ git merge BranchName
# How do I merge a version of a single file from one git branch to another?
$ git diff --stat myBranch # show the difference file between current branch to myBranch branch
$ git checkout --merge develop target.txt
#merge target.txt from develop. Ex : $ git checkout --merge develop Web/Scripts/options/options.routing.js
$ git diff --stat myBranch # now you dont see the merged file (target.txt) in the file difference.
# Cherry picking in Git means to choose a commit from one branch and apply it onto another.
# Step-1: Make sure you are on the branch you want to apply the commit to.
$ git checkout master
# Step-2: Execute the following:
$ git cherry-pick <commit-hash>
$ git mergetool
$ cat FileName
# Open file using notpad
$ start FileName
$ git checkout BranchName # For local
$ git checkout origin/BranchName # For remote
$ git checkout -b BranchName
$ git branch -m OldName NewName
$ git checkout feature-2
$ git checkout -b arif/feature-2 #This branches will be create under arif directory
$ git branch -d feature-2
$ git checkout FileName
$ git checkout -- .
$ git config user.name
# Show the commit of current user
$ git log --author="$(git config user.name)"
$ git log --committer="Arif"
$ git reset --hard origin/master
# To move a individual commit / Move head to a point. This will destroy any local modifications. Don't do it if you have uncommitted work you want to keep.
$ git reset --hard #### ($git reflog to get the desire point)
Ex.
$ git reset --hard 055c61b
# Then to push remote forcefully
$ git push Origin BranchName -f
$ git branch -a # All branch
$ git branch # Local branch
$ git branch -r # Remote branch
$ git branch -a | grep 'search keyword' # Search branch
$ git for-each-ref --format='%(committerdate:short),%(authorname),%(refname:short)' --sort=committerdate refs/heads/ | column -t -s ',' # show branch with date
$ git stash # Save something to move another branch
$ git stash apply
$ git stash pop # git stash pop = git stash apply && git stash drop
$ git stash list # Show all list of stash
$ git rm -r one-of-the-directories
$ git commit -m "Remove duplicated directory"
$ git push origin master
$ git rm -r --cached myFolder
git mv casesensitive tmp
git mv tmp CaseSensitive
# Using Command Prompt
> cd E:\Documents(Programming)\Asp.Net\AspMvcPractice
> ren .gitignore.txt .gitignore
#OR
$ touch .gitignore
$ git add .gitignore
$ git commit -m "add .gitignore file"
# change URL in .git/config file
# https://youruser:password@github.com/user/repo.git
# Show the author Info
$ git config --list
# Show different config (global, user, repo, etc...)
git config --list --global
# Add Email and UserName
$ git config user.email "arif.rahman2009@gmail.com"
$ git config user.name "Arif"
# --soft indicates that the uncommitted files should be retained as working files opposed to
# --hard which would discard them.
$ git config --list --show-origin
# To see a list of which commits are on one branch but not another, use git log
$ git log oldbranch ^newbranch --no-merges # show commit logs for all commits on oldbranch that are not on newbranch
# Viewing Unpushed Git Commits (view all commits that doesn't exist in origin/master)
$ git log origin/master..HEAD
or
$ git log --branches --not --remotes
# You can also view the diff using the same syntax
$ git diff origin/master..HEAD
$ git diff --name-only 543840a..e1aacf1
# Show local commits in a branch :
$ git log origin/BranchName..BranchName
# Get commits only for a specific branch (mybranch - develop):
$ git cherry -v develop mybranch
# This would show all of the commits which are contained within mybranch but NOT in develop.
# if you leave off the last option (mybranch), it will compare the current branch instead.
$ git diff # show uncommitted changes
$ git commit --amend
# Unstages the file in the current commit.
$ git reset <file> # Example : git reset <viewmodel.js>
# Unstages the file for future commits also. It's unstaged untill it gets added again with "$git add <file>".
$ git rm --cached <file> # Example : git rm --cached <viewmodel.js>
$ git show <revhash>
$ gitk <revhash>
$ git show --pretty="" --name-only <revhash> # It will show only name http://stackoverflow.com/a/424142/3835843)
# Tag is a Lighter weight machinist than branch. It represents a version of a particular branch at a moment in time. It's like save point in database.
$ git tag 1.1.0 # Create tag named 1.1.0
$ git tag -a 1.1.5 -m "New release" # Create tag 1.1.5 with a message
$ git tag # To show already created tag
$ git show-ref --tags # To ahow the tag location
$ git tag 1.1.0 -d # Delete tag 1.1.0
$ git push --tags # push tags to remote
$ git tag -n9 or git tag -l -n9 #it will list all the tags along with annotations & 9 lines of message for every tag
$ git tag -l -n9 v3.* # will only display tags starting with "v3."
# If .gitIgnor gile not working
$ git rm -r --cached .
$ git add .
$ git commit -m "Fixed untracked files"
-h for command help. Ex- $ git log -h
GIT SCM https://git-scm.com/download/win
GitGuys http://www.gitguys.com
Github Markdown Cheatsheet https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
Generate SSH Key https://github.com/shibbir/notebook#generate-ssh-key
Arifur Rahman ( arif.rahman2009@gmail.com )
The MIT License Copyright © 2017 Arifur Rahman