Git Utilities and hacks

Although GIT is an old topic, still i am adding a collection of basic and useful git utilities and hacks that is helpful in day-to-day git cli interaction.

Reference to learn git command and usage

https://gitimmersion.com/

Setting up default credential

to setup the credential, we can create a .git-credentials file user home directory

https://<usernmae>:<password>@bitbucket.org
https://<usernmae>:<password>@github.com

these will be used during remote operation

Setup alias to the git command

to setup the alias, we can create a .gitconfig file at the git project

[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
  type = cat-file -t
  dump = cat-file -p

after setting this up, you can execute the command line

>>> git hist # instead of git log that will show a formatted output

You can also define some other config as well

[user]
	name = chandra
	email = chandra
[cola]
	spellcheck = false
[credential]
	helper = store
[core]
	filemode = false

you can define this under user home directory to be effective at all or project wise as well

Ignoring some file [Project wise]

You can create a .gitignore file at root of the project to ignore some of the files from being part of the repo

# Node artifact files
node_modules/
dist/

# Compiled Java class files
*.class

Git repo options at local [project-wise]

Config

you can edit the file that is available under your local git repo at the path

.git/config

Hooks

You can also write shell script that can be called during git command interaction and you can put them under .git/hooks

like , execute some command before commit or after commit

There are already sample available, you can rename them

Leave a Reply

Your email address will not be published. Required fields are marked *