Git tricks you should know

We use version control system to manage and gather our source codes, right. I am pretty sure most of us are using Git for version control system nowadays. Today, I will share with you some git commands that will help you to improve your git knowledge.

Remove all your local git branches except master

You may have many local branches while you are on developments. But one day, you may want to get rid of these local branches and keep only main/master branch. This command will help you.

git branch | grep -v "main" | xargs git branch -D

Undo last commit

If you want to undo your most recent commit. Follow these steps.

git commit -m "undo message"

Then reset our changes

Pretty git log format

git reset HEAD~

Normally we use to see our git log activity using git log. But we can see better with pretty formatting using this.

git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

Deleting git branch

I wrote deleting local branches except main/master in above. In here, I will talk about deleting a specific branch both on local and remote.

Deleting on local

git branch -d <branch_name>

Deleting on remote

git push <remote> --delete <branch_name>

Cherry picking from another repository

We can apply the changes from another repository to us also.

git fetch <remote-url> <branch_name> && git cherry-pick SHA1

I’m pretty sure there are other useful tricks as well. That’s all for now.

Yuuma



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム