Most useful Git commands. Git tips

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…

Read More


How to rename local branch in Git

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

Read More


View changes before commit in Git

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…

Read More


How to create branch from tag name in Git

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…

Read More


How to delete Git branch both locally and remotely

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 git br…

Read More


How to undo all uncommitted changes in Git

You can undo all uncommitted changes in Git using git checkout command with -f parameter #undo all uncommitted changes in git git checkout -f

Read More


How to find list of files which are different between two branches in Git

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…

Read More


How to merge branches in Git without auto commit

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

Read More


How to revert file to previous commit version in Git

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…

Read More


How to undo last commit in Git

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 …

Read More


Social media

Search

This blog is a place where I share new and cool stuff related to Software development