๐Ÿ–ฅ Useful Github commands with use case

ยท

3 min read

๐Ÿ–ฅ Useful Github commands with use case

What is the goal? ๐ŸŽฏ

If you are an open-source contributor, starting a new journey to contribute to open-source projects, or joining a new company, then knowing these GitHub commands will go handy.

List of Github Commands ๐Ÿ“‹

Check status ๐Ÿ”Œ

It is always good to see the status of the local repo before starting work or committing the code. git status will list the modified and uncommitted files.

git status

Current working branch ๐ŸŒต

Almost every open source projects have many branches of the project for example main, dev, fix, etc. So you have to check on which branch you are currently working. by running git branch we can get a list of all branches and the highlighted with star* which indicates the current branch.

git branch

Create a new branch ๐Ÿ“‘

This is a common use case where you want to contribute/work on the open-source or company project then you have to create a new branch and then you can work or add a new feature on the new branch rather than working on the main branch. This command will create a new branch from main and will switch to a newly created branch.

git checkout -b <new_branch_name>

and if you want to create a new branch from a specific branch then you can use the following command.

git checkout -b <new_branch_name> <target/specific_branch_name>

Switch Branch ๐Ÿ“š

You will be switching between different branches. So to switch the working branch use the following command.

git checkout <branch_name>

Merge specific branch โ›“

You are working on a branch for adding new features but the main branch is also got other new features and if you want to pull that new changes into your working branch then you can use the following command. first, switch to your branch. And run the following command. It will merge the specific_branch to the current branch.

git merge <specific_branch>

Change recent commit message ๐Ÿ’ฌ

Let's say you committed a recent change in your local project but unknowingly by mistake you misspelled in commit message or somehow wrote the wrong commit message and not yet pushed it to the remote, then you have to correct the commit message and then push to a remote branch.

So we have a command for that. The following command will open an editor to write a new commit message.

git commit --amend

We can change the new commit message inline without opening the editor by using the following command.

git commit --amend -m "new commit message"

Conclusion ๐ŸŒ

These commands can go handy apart from basic commands like add, commit, etc.

If you found this blog helpful consider following ๐Ÿค.

Thanks for reading โค๏ธ

ย