This is just a short collection of Git commands and tricks which I personally did not always remember.
Create a new Tag
To create and push a new tag:
1.) List current tags
$ git tag
2.) Create a new Tag
$ git tag -a <TAG-VERSION> -m "next release"
3.) Push tag
By default, the git push
command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them.
$ git push origin <TAG-VERSION>
Create a Branch
To list all existing branches:
$ git branch
to create a new local branch
$ git branch <branch>
and checkout it with
$ git checkout <branch>
to push the branch to the remote repo
$ git push origin <branch>
Merge a Branch
Merge another branch into the current (e.g. into the master branch)
List all the branches in your local Git repository using the git branch command:
$ git branch
The output shows all branches and marks the current branch with an *.
Ensure you are on the branch you want to merge into. To switch to the master branch:
$ git checkout master
Now you can start merging. Since merging is a type of commit, it also requires a commit message.
$ git merge -m "Your merge commit message" [source_branch]
Check the result in your current file tree.
Finally push your changes:
$ git push origin
How to resolve Merge Conflicts
Sometime you may forget to pull before you start working on something. Later you can not push your commit directly if a colleague has worked on some other artifacts. In this case you can do pull --rebase
. This will resolve the conflict in most cases.
$ git pull --rebase
you can also set this behavior as default if you change your global git settings:
$ git config pull.rebase true
In any case if your pull produces a merge conflict you still will be warned by git.
One Reply to “My Git – Cheat Sheet”