GIT tips and best practices!
14 Mar 2015 |
Git
will be updated frequently. Last updated on 21-April-2015
- Amend: If you miss some file in last commit, then use –amend switch. Add the missed files to stage, then commit with amend switch. This will add the file to previous commit.
git commit --amend
.
- Donot commit half-work to main branch. For development activities, always create seperate branch and commit often in the branch. Once testing is done, commit to main branch.
- Donot use Amend in published work (already pushed to server). Doing so, the further commit push will be rejected by server. Pulling from server to update local copy will result in merge conflict.
- Some thing got messed up after last commit? If you don’t want the changes, then use
git reset --hard
. If you want the changes to store some where else for a while, use git stash
. git stash pop
will bring those changes afterwards.
- Have plugins for your editior/IDE to do code format automatically. This will reduces the unnecessary changes in files due to code formatting in later point of time.
git log
show the log messages. git log --oneline
will show the log messages with hash and commit message. To exit log terminal, type q and hitenter
.
- Shallow Cloning: While cloning,
depth=1
tells git to download content with latest commit history alone. git clone --depth=1 http://www.github.com/username/repo.git app
- If you get Fatal: Authentication Error while pull/push, use this command to renew cached credentials
git config --global credential.helper wincred
- If above command does not works, go to Run prompt, and type
rundll32.exe keymgr.dll,KRShowKeyMgr
, Windows Credential Manager will open, delete all the entries related to git repositories. This will deletes all cached credentials.