This article will help to understand the Git system via the command line. Before discussing the basic commands of Git, let’s see the short brief about Git.

Git is a modern and widely used open-source Distributed Version Control system in the world. It is developed to manage projects at a personal level as well as at the organizational level with high speed and efficiency. The version control system allows us to monitor and work together with our team members in the same workspace.

We can perform the operations from different operating systems such as Windows, Linux, macOS. It is easy to learn, which helps to track or work together in the same repositories. It is secure, has fast performance.

Let’s begin with the Git workflow, then after move on to useful commands for developers.✌


1. Git Workflow

We have already talked about Git (earlier in the article), which helps to tracks and work on the same workspace that developers or organizations use to collaborate on developing applications.

Git Project has three different sections,

  • Working Directory: The state where we perform add, delete, modify operations on files.
  • Staging Area: After modifying the files, we need to stage or commit the changes before pushing them into the Git directory.
  • Git Directory (Repositories): The section where Git stores the committed changes in the repositories.
git sections
Git Architecture

2. Git Basic Commands

Git has many commands, but those that are useful or mainly used by developers or programmers in the workspace are:

$ Git Init
  • If you are creating the new local repository or if you want to create the new directory in a specific project, then you need to initialize git; only then you will be able to commit or adding the files.
$ Git Clone
  • If you want to copy the directory from remote directory then use:
$ Git Status
  • This command returns the current state of the repository. If your files are in the staged area and not committed yet, then git status shows your files.
  • It shows us in two different categories – Staged and Unstaged. Staged means you have already added the file in the staged area. And Unstaged means not added yet. It is a must to use before doing any commit or adding the files.
git-status
$ Git Add
  • It helps to add the files in the staged area for Git. We can perform git add in various ways, like if you want to add the whole directory or multiple files or all files. Before committing, it is required to add the files in the staging area:
  • To add few files:
  • Add all files:
  • If you want to add whole directory: (let say templates folder)
$ Git Commit
  • It creates the changes made to the files and saves them to the local repository. It has created the commit’s unique ID. We should also add some message at the time of the commit to get to know the other team members about the change.
  • If you want to write longer commit message, this command will open the editor:
  • Modify commits, If you want to modify the recent commit message or add the files then use --amend
$ Git Checkout
  • It is used to switch the branch to another branch.
  • For create new branch,
  • Undo all the changes
git checkout
$ Git Push
  • It pushes the local changes of the repository to remote repository.
  • Using upstream, push the local changes as the new branch of the remote repo if not exist.
git push
$ Git log
  • Used to see the commit history, it displays Date, Author Name, SHA, Author Message. It helps give context and history for a repository.
  • You can get the list based on Name or Date also.
git log
Logs list
git log date
Logs using date
$ Git Pull
  • To get the latest version of the repository. It would be up to date your local repository to the same as on remote repository.
$ Git Stash
  • This command will temporarily store the changes which are not yet ready to commit and give a clean working directory.
  • You can use these change later or any time in the current branch by using pop
$ Git Rm
  • It can be used to remove files from the Index and working directory (cached).
  • To delete a file forcefully.
$ Git Diff
  • It helps to see the difference between the base branch and the current branch, displays the modified files that are not added to the staging index.
$ Git Reset
  • This command will reset the index and the working directory to the last git commit.
$ Git Merge
  • Used to merge the base branch into your active branch to keep up to date with the current branch.
  • Suppose you want to merge the main branch into your current one then:
$ Git Config
  • Used to set the user-specific configurations like name, email, the format of the file, and so on. To set up the name or email, we use:
git config
Set Username like this

So, that’s all about the basics as well as important GIT commands that developers should know.

I hope you enjoyed the article and if you found it useful, please share it with your friends and colleagues. If this post helps you, then spread this so that other people can also benefit.

If you have any queries please feel free to post them in the comments section or anything that you want to ask through mail contact.

Thank you😉. Happy Learning 🙌🏻

Also read: