Top 12 Git Commands Every Developer Should Know

I work as a software engineer developing software mainly with React.
Search for a command to run...

I work as a software engineer developing software mainly with React.
No comments yet. Be the first to comment.
Authentication is critical to modern web applications, ensuring secure access to resources and user data. AWS Cognito is a powerful tool that simplifies authentication while offering scalability and ease of integration. In this blog, we will walk thr...
In the world of modern web development, maintaining clean, readable, and efficient code is paramount. As projects grow in complexity, so do the challenges in ensuring code quality and readability. This is where tools like clsx step in, offering devel...

In the realm of React development, the choice of UI frameworks significantly impacts design consistency, developer experience, and scalability. The decision between Material UI (MUI) and Tailwind CSS demands a deep understanding of their respective a...

Understanding the Motive Behind Hacks: Not all hacks are personal attacks. Some are opportunistic, targeting those who may not be as cautious. Cybercrime is a thriving business, where perpetrators aim to transform you from a 'lead' to a 'paying cust...

State management is a fundamental aspect of building robust and scalable applications. Two popular solutions have emerged in React to handle state: Context API and Redux Toolkit. Both approaches aim to make state management more efficient and maintai...

In this blog, we will learn Git, a free and open-source distributed version control system designed to handle everything from small to large projects quickly and efficiently. In simpler words it lets you manage and keep track of your source code history. Don’t mistake Git for GitHub, GitHub is a cloud-based hosting service that lets you manage Git repositories. Even I and millions of people use GitHub. Before we begin, let's download Git on our computer Git - Downloads (git-scm.com)
Are you excited? No? But I am and you should be too because every interviewer will ask you about it and in the future, you will do the same. I have serially listed the git commands below.
Git init creates an empty Git repository or reinitializes an existing one.
Syntax:
git init
Git config commands to set your username and email. Git requires that a username and email be established before you can leverage all of its capabilities.
Syntax:
git config -- global user.name “John Doe” - This set the username.
git config -- global user.email “johndoe@example.com” - This set the email address.
The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.
Syntax:
git add <file_name> - This adds a specific file.
git add <directory_name> - This adds a specific directory.
git add . - This adds all the unstaged files.
The git commit command is used to keep track of our progress and changes as we work, git considers each commit change point or save point. It is a point in the project you can go back to if you find a bug, or want to make a change.
Syntax:
git commit -m “ message” - This git commit command performs a commit, and the -m “message” adds a message.
The git push command uploads local repository content to a remote repository. Remember Github? It is also a remote repository. Contents on the GitHub repository can be shared with friends and even they can contribute to your project or vice versa.
Syntax:
git push origin master - This pushes the content to the “master” branch of your remote repository
The git status command displays the state of the working directory and the staging area, it lets you see which changes have been staged, which haven’t, and which files aren't being tracked by Git. Remember this will not show the committed project history.
Syntax:
git status - This displays the state of the working directory.
The git branch command is used to create a branch, delete a branch, and list all the branches that have been created or are available in the repository.
Syntax:
git branch -a - This will get all the branches that are available in our repository.
git branch <branch name> - This will create a new branch.
git branch -d <branch name> - This will delete a branch.
The git checkout command is used to go to switch between the branches.
Syntax:
git checkout <branch name> - This switch to an existing branch.
git checkout -b <branch name> - This will create a new branch and switch to this new branch.
The git merge command is used to integrate one branch into another branch. Usually, we integrate the feature branch into the main branch of a repository.
Syntax:
git merge <branch>
The git clone command is used to create a local copy of an existing remote repository.
Syntax:
git clone <URL>
The git pull command is used to get the latest changes made to a remote repository.
Syntax:
git pull <branch name>
The git stash command is used to store the changes made in the local repository which was not committed. This is very useful when you want to pull some changes from the remote repository which was committed by your friend and want to merge it with your source code.
Syntax:
git stash - This will save modified and staged changes.
git stash list - This will list out our stashed file changes.
git stash pop - This will bring back our temporarily stored files.
git stash clear - This will temporarily delete stored, modified, and tracked files.
We now know some of the most crucial Git commands to increase productivity. Use these Git commands in your regular coding activities. If you have learned all 12 of the aforementioned instructions, there are many more. Here is a link to the official Git - Reference webpage where you may learn about the other commands. Hope to see you in my next blog. Thank you.