most used and useful commands for git

There are some really useful and usually used commands in git, here i made i little list of them.

checkout [branch]

Checkout it'll help you to move between other branches. If you want to create a new branch when moving you have to add the -b command followed by the branch name, like this:

- checkout -b new-branch


A way to list all your branches you may want to use branch -r to see the remote ones, branch -a to see them all, and branch without params to see only the local ones.


When you work on a new task you may want to create a new branch but then when you have finished you have to merge it with the master, to do so you have to go into the master branch and type

- git merge brench-task-done

Doing like that all the things that you have done into that branch will get merged, but, before pushing test what you have merged so you check that all is working fine.

The reason why may things no work is that, if you are working with other people they may have merged other stuff too that you are not aware of and possibily can break you code... or maybe they have touched files that you have worked on.


Sometimes you may find the need to reset every local change made, to do so you have to type:

- git reset --hard HEAD

versioning version control system github gitlab top git commands git versioning versioning tools
Expand your knowledge about this topic