Over the last few years working with Git source control system, I found a number of useful git commands which helped me a lot to solve non-trivial tasks related to Git source control system. I don't use this tips every day, usually it's only one or two time I used them in total, but knowing those gi…
If you want to rename local git branch you can do it using the following command
git branch -m old-branch-name new-branch-name
If you want to rename your current git branch you don't need to provide old branch name
git branch -m new-branch-name
Usually before committing changes in Git developer verify one last time all changes he did. Normally we use git difftool command in order to do it. In that case git will ask you a question if you want to see changes before opening each file. When the number of changed files are big or when different…
Usually after deployment to production environment a new tag created in git marking successful production deployment, so later when working on defects it would be much easy to investigate any issues, having the same code as deployed to production. The best way to work with git tags is to create new…
Delete Git branch locally can be done providing -d parameter to git branch command. In some cases git can complain than branch is not fully merged, and it will refuse to delete it, in that case you can use -D parameter (capital D), it will force Git to remove it.
# remove git branch locally
You can undo all uncommitted changes in Git using git checkout command with -f parameter
#undo all uncommitted changes in git
git checkout -f
You can compare branches in git using git diff first-branch..second-branch but this will give you all changes between branches, but sometimes you need to know only files which were changed. You can do it using the following git command, it will give you list of files names changed between two branch…
When doing merge in Git, it automatically commit merge result if no conflicts exists. That behavior can be changed when --no-commit parameter provided.
How to merge in Git without commit
git merge branch-name --no-commit --no-ff
When you modified, but did not commit file and want to revert your changes, you can use git checkout command providing file name or wildcards to revert, for example, all files of the same type.
How to revert single file in git
git checkout path-to-file
How to revert group of files in git
# git c…
There are a number of ways to undo changes you commit into git repository, it depends on what exactly you want to change or undo and how.
For example, the most common task is change comment text for your commit, in this case you can follow instructions from How to change last commit message in git