Welcome to my #codingboard. Today I will be sharing the top 10 git commands that I use daily at my job as a front-end developer. However, before we dive into this, I just wanted to mention that Git has become a very essential tool for any developer, and knowing these Git commands and what they do, will be very helpful and useful for your productivity at your place of work (that is if you use Git btw and if you don't, you can still learn about Git because I think that they are very important and useful)




Note: This is just a short list of the top 10 git commands that I use daily. That being said, I use other git commands aside what I've mentioned in this article but the reason why I'm limiting this to ten is because I feel that as a newbie, you may not know the most important Git commands to know considering that there is a lot but knowing this first ten will be a great start.

So, let's dive right into it. My top 10 git commands (in no particular order) are:


1. git status: This command shows all the changes you have made to your local (all the files that you have modified). The files will be organized as changes that were staged and unstaged.

git status


2. git branch: This command can be used to show all local and remote created branches. It also shows the branch that you are currently working on. You can use this command to delete a branch and rename your branch aswell.

//list all branches
git branch or git branch --list


//list all local and remote branches
git branch -a


//delete a branch
git branch -d <branch-name>


//delete a branch with unmerged changes
git branch -D <branch-name>

//rename a branch
git branch -m <oldname> <newname>


3. git add: This command is used to stage modified or untracked files

 //to stage ALL untracked files
git add .

 //stage a specific file
git add <file_name>


4. git restore: This command is used to unstage or discard the changes you previously added to the staging area and also discard local changes in a file (i.e restoring last committed state) 

 //to restore ALL files
git restore .

 //to restore specific files
git restore <file_name>


5. git commit: This command saves the changes in your local repository. Basically used to commit staged files. Before committing your changes, you have to include a message that describes what changes you did. This becomes handy if somebody else needs to work on that file in the future and also useful when a pull request is sent (your reviewer will have a quick overview of what you did)

git commit -m <message>


6. git push: This command pushes your committed file changes from your local repository to the remote repository. This is like your first step to creating a pull request (sending your work to the remote). This command also creates a remote branch for you if it doesn't exist.

git push origin <branch-name>


7. git pull: This command updates the most recent changes to your local repository so that you can have the latest update from your teammates

git pull origin <branch-name>


8. git stash: This command temporarily shelves(or stashes) your changes to a working copy so that you can work on another branch and then come back to that same branch when ready to continue from where you stopped. As an example, let's say you are working on a file in a branch and you find a small bug in a separate file that needs to be fixed quickly. You can run your git stash command to store your current work temporarily in a hidden directory. Once you git stash, you will be able to switch your branch to fix the bug. Once the bug is fixed, you can then return to the previous file and switch branches. I always use this command when i'm not ready to commit my changes yet.

//to stash your changes temporarily
git stash

//to restore your stashed changes
git stash pop


9. git checkout: This command is used to create and switch to a new branch or just switch from one existing branch to another. Before you checkout to another branch, make sure that all the changes in your current branch has been committed or stashed.

 //create and switch to a new branch
git checkout -b <branch-name>

//switch to an existing branch
git checkout <branch-name>


10. git merge: This command is used to combine your branch with the parent branch. The parent branch can be either a development or main branch depending on your workflow

Note: Before merging, always update your local branch by pulling from the parent branch or main. This is because your teammates might have made some changes to the main while you were working on your branch to avoid conflicts in the future

git merge <branch-name>


That will be all from me today. I hope you learnt one or two things from this article as much as I enjoyed writing it down. Have a beautiful day and thanks for stopping by. Cheers 🥂


Funny Quote:- "Incase of fire, git commit, git push, git out ” ~ Author Unknown

HAPPY CODING!!! ❤️

SHARE 0 comments

Add your comment

© Wemi's Coding Board · THEME BY WATDESIGNEXPRESS