Mastering GIT is a real challenge to every developer, specially when we talk about high level git commands when we rebase/merge, revert commits or clean merged branches after merging.
There are some commands that we always use but there are ways to raise their uses to an advanced level.
Init with an empty commit
It’s a good practice to initialize git with empty commit. to do that we need just to add –allow-empty after commit.
git init && git commit -m “Initial Commit” --allow-empty
Status with Short branches
Git status is the most used command to see what files are changed and what branches we are working on. But using git status will return a long story to tell us what to do.
We can -bs flag or –short –branch to see changes in only few lines with the specific branch name.
Personally, I created an alias command “bs” but the git command is:
git status -bs
Stashing untracked changes
When you are working on a project and somehow you need to switch to another branch or pull the branch to get latest updates, it’s useful to stash your local changes BUT git stash only don’t stash untracked changes so you need to add this flag –include-untracked
git stash --include-untracked
Force with lease
We should never use force with git and it’s only permitted when we modify commits history after a rebase. So, there is another way to say that gently when pushing to remote repository:
git push --force-with-lease
This command checks that your local copy of the refs that you’re overwriting is up-to-date before overwriting it.
Graphic Log
We need sometime to check git logs to get infos about our branches but it’s urgly and with a huge team log will be painful. That’s why we need to check git graph in github/Gitlab/bitbuckets.
To get a nerd graphical git log on the terminal I personally I create an alias git glog that means graphic log:
git config --global alias.glog 'log --graph --abbrev-commit --decorate --all --format=format:"%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)"'
That’s it folks, if you have another git commands just leave a comment bellow, I’ll appreciate it. I hope you enjoy it