Git useful commands

Created at: 2019-09-10 14:12:34 Updated at: 2020-05-23 15:33:20

in Git, Linux

  • Store all your cred into system helper
    git config --global credential.helper store
    # Set the cache to timeout after 1 hour (setting is in seconds)
    git config --global credential.helper 'cache --timeout=3600'
  • Reset current branch to previous stat
    git reset --hard HEAD
  • Ignore file mode change in current working tree
    # For individual project
    git config core.fileMode false 
    # For system wide all git project
    git config --global core.fileMode false

Git log for branch

git log --pretty="format:[%an] => %h %ar %s"

Get branch history

git log <<YOUR BRANCH NAME>> --pretty="format:[%an] => %h %ar %s" >> mergehistrory.txt

Get project HEAD commit

git rev-parse HEAD

Merge with single commit

git merge --no-ff <<YOUR MERGE BRANCH / origin/branchname>>

Git useful aliases


# Work email for git config
git config --global alias.personal 'config user.email vrkansagara@gmail.com'

# Personal email for git config
git config --global alias.personal 'config user.email email@work.com'

# List of untracked files
git config --global alias.untracked ls-files --others --exclude-standard

# List of modified files.
git config --global alias.modified 'ls-files --modified --exclude-standard'

# List of deleted files from git
git config --global alias.deleted 'ls-files --deleted --exclude-standard'

Final my .gitconfig file looks like

    [user]
        email = vrkansagara@gmail.com
        name = Vallabh Kansagara
    [credential]
        helper = store
    [core]
        fileMode = false