My most commonly used git commands ( apart from the basics )

Hello guys, how are you doing?
It’s been quite some time since I started to think about writing here at Medium.com and I confess that I didn’t have a clear idea of which topic to choose in order to share valuable knowledge with others.
So I thought: Why don’t I start with the basics? What tools do I use everyday? And then, this article come to my mind. My goal here is to share my most common used git commands and explain then. I hope this helps you and it’ll also work as a documentation for me for future check.
So let’s start.
The first command that I often use is:
git merge --no-ff "target_branch"
This command allows you to merge your current branch with the target branch by creating a merge commit point even when it’s a fast-forward merge. It helps keeping the record of all performed merge commands in the concerning git repository and it also makes easier to revert a merge, in case of necessity.
git remote update origin --prune
This command update the local list of remote branches. The --prune
parameter tells Git to remove any remote-tracking names that exist in your repository, but no longer correspond to a branch name in the repository at remote
.
git branch | grep -v "master" | xargs git branch -D
This command above is very helpful. It deletes the list of your local branches except from master. It’s a fast way to clean some old local branches.
Below, are two commands that I often use together every time that I need to reset a branch in remote
.
#1 git reset --hard "commit_hash"#2 git push --force origin "target_branch"
The first one will reset the branch history to the “commit_hash” specified. Then you can use the second one in order to push this “update” into the branch remote.
And finally, at last but not least
#1 git commit --amend#2 git clean -fd
git commit --amend
will allow you to edit your commit message. This helps a lot when you forget to use the git flow syntax. Who never did that, right? hahah
git clean -fd
will clean for you any untracked files that often appears and you don't want to commit then.
That’s it guys!!
I hope these commands helps you as well as it helps me. Nice coding!!