Skip to content

7 basic git commands you should know

Git is an open-source version control system used heavily in software development. When working with a large team, version control of the project becomes necessary, bringing git into the picture.

It may get a bit difficult for a new developer to understand git initially. There are many commands in git that you can use. Let’s see some basic git commands that every developer should know.


git clone

The git clone command creates a copy of your remote repository into your computer. The copied repository on your system is linked with the remote repository so that you can regularly update your changes and access the changes done by other developers in the remote repository.

Syntax
git clone <link to your repository>
Screenshot of git clone command

Also read: How to remove a remote Git repository?


git checkout

You can have multiple branches in your git project, and depending on the feature you are working on, you may have to switch between branches. In such a scenario, you use the git checkout command.

Syntax
git checkout <branch name>

You can use the ‘-b’ option to create and switch to the branch you just created.

Syntax
git checkout -b <new branch name>
Screenshot of git checkout command

git status

The git status commands show you the current status of your repository and current branch. It tells you about the tracked files, the staged files, changes are made, any new or deleted files. It tracks your repository and current branch.

Syntax
git status

The example here shows the output of the git status command, where initially there was no change and the repository was up to date. Later, after some changes, the git status command showed changes in the file.

Screenshot of git status command

Also read: How to rename a branch in Git? Local and Remote


git add

The git add command adds your new, modified file into the staging area. It tells your Git to track the new or modified file. If you don’t use this command, the git will not track any new file you create or the modified file, and your changes will not add to the commit.

Syntax
git add <file name>

You can use the ‘-A’ option to add all the files to the staging area.

Syntax
git add -A

git commit

You use the git commit command when you want to save the changes. Commit is like a checkpoint where you can roll back later on if you’re going to undo the changes. This command saves the changes in the local repository in your system.

Commit allow you to add a message with your commit using the ‘-m’ option.

Syntax
git commit -m "Type your message here"

Also read: What is DevSecOps? DevOps vs DevSecOps


git push

When you want to send your changes to the remote repository, you use the git push command. This command pushes only your commits to the remote repository.

Syntax
git push <remote> <branch name>

git pull

The git pull command fetches all the latest updates from the remote repository into your local repository.

The git pull command can give you some conflicts which you will have to resolve manually.

Syntax
git pull

Also read: How to remove untracked files in Git?

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.

Share on facebook
Share on whatsapp
Share on twitter
Share on reddit
Share on linkedin
Share on pocket
Share on pinterest
Share on telegram
Share on stumbleupon
Share on digg
Share on tumblr
Share on email
Share on skype
Share on xing
Share on vk
Share on odnoklassniki
Share on mix






No more posts to show


>