Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Updated
3 min read
Git for Beginners: Basics and Essential Commands
  • What is Git

  • Why Git is Used

  • Git Basics and Core Terminologies

  • Common Git Commands


Understand GIT and its Uses

Git is a version control system that manages operations like modifications, updates, changes, removals, history, and many more in a specific folder, repository, or directory. ( Folder , Repository and Directory are having same meaning )


What are the Terminologies used inside Git ?

  • Repo - It's like a folder where your files are stored.

  • Staging Area - When you update your files and want Git to track them, you move the specific file to the staging area.

  • Commit - When you are ready to save the updated changes of a particular file, you first need to commit that file, and it will then be added to your repository.

  • Branch - It's like different timelines existing together but not affecting each other.

  • Merge - When you want to bring content from a different timeline (Branch) into your timeline (Your Branch), you need to merge it.

  • Head - It's like a marker or pointer that shows your current location, position, or what you are currently working on.

  • Commit History - It's like a record of everything you have done in your file, including updates, removals, additions, merges, modifications and many more.


Common Git Commands

  • git init -Turn your folder into a Git repository by initializing a .git file inside it.

  • git add <your fileName> - Will place your file in the staging area, making it trackable.

  • git add . - Will move all the files in the working folder to the staging area, no need to mention specific names of the files.

  • git commit -m “Your message” - This will save your final changes to the repository.

  • git commit -am “Your mesage” - This is a very important command to know. It first pushes the files into the staging area and then commits them with a message. The "Cache"is that this command only pushes files into the staging area if they are already being tracked by Git. So, if you create a new file and run this command, it won't push the new file into the staging area. However, if you have modified files, it will work on those.

  • git branch - Shows you which branch (timeline) you are currently on.

  • git status - This command will show you the status of your files, such as which ones are tracked, untracked, or modified.

  • git log - Provides the complete history of your files and the operations you have performed so far.

  • git revert <hashId> -Will make a complementary commit for the changes that happened in the mentioned <hashId> and won't remove the history.

  • git reset —hard <commitId> - This is similar to revert, but here no complementary commit is created. It simply removes all the history and takes you to the specified <commitId>.

There are more command that exists you can check them on Git official documentation.


Flow Diagram of Commit History


Conclusion

We understand the terminology of Git, the staging area, branches, commit history, and various Git commands.