This is part of Git series and I hope you have already completed part 1 and part 2.
We have covered most of the usual scenarios. In this chapter we will cover some of the best practices and how to recover from unlike events.
It is a good practice to have smaller commits. Event bigger features can be developed in increamental model. Smaller commits are easy to revert and less chances of hiding bugs.
Do not commit generated files. Maintain .gitignore file at the root of the folder and update all the files and folder that should not be tracked hence need not be committed.
Always maintain .env file to store passwords or secret key. We sometime hardcode it in the source code. People can misuse your credentials. Be careful.
Do not rely on your memory. The moment you resume your work inside the repository, type these two commands.
$ git branch $ git status
I know you might be wondering why first command when second command is enough to tell the branch info as well. But git status might return many lines of information and chances are more to miss what branch you are in currently. Anyway, these two command will tell you, the status of the branch you are in currently. You might have uncommitted code or unpushed changes, this will be helpful for next step.
This is very common miss from the developers. Typing git push and thinking nothing is left from his/her side. Remote repisotory might be ahead if someone already pushed code when you were developing your feature. You need to first git pull and merge locally and then git push. Otherwise, git push will fail and you might miss the error thinking push is successful.
$ git pull $ git push
Suppose you wish to undo a particular commit due to some reason. Undo does not literally remove from the git history. Rather it reverts that changes and creates another commit(history).
$ git revert <commit_hash>
For detailed info on git revert. Refer this
Quick Links
Legal Stuff