Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Git: The Basics

Posted on Jul 28 • Originally published at wizardingweb.hashnode.dev In the world of software development, version control systems are an indispensable tool for managing code changes, collaborating with others, and keeping track of project history. In the previous post of this series, we discussed the importance of version control systems, and their types, and introduced some essential terminologies. In this post, we will focus on one of the most popular version control systems, Git, and its basics. Understanding the fundamentals of Git can help you streamline your workflow, avoid common pitfalls, and collaborate more efficiently with your team. So, let's dive in!Git is a distributed version control system that was created by Linus Torvalds in 2005. It's incredibly popular due to its flexibility, speed, and ability to handle large codebases. With Git, developers can work on the same codebase simultaneously, and easily switch between branches to work on different features or fixes. Git also provides a wide range of tools to help with collaboration, such as merge requests and pull requests.Git is different from other VCS because it thinks of its data like a series of snapshots of a miniature filesystem rather than a list of file-based changes. Git stores data as snapshots of the project over time.In Git, nearly every operation is local because most operations only require local files and resources to operate. This means that it is very little you cannot do if you are offline.Git has integrity because everything in Git is checksummed before it is stored and is then referred to by that checksum. Git uses SHA-1 hash to store everything in its database not by file name but by the hash value of its contents.When you do actions in Git, nearly all of them only add data to the Git database. It is hard to get the system to do anything that is not undoable or to make it erase data in any way. After you commit a snapshot into Git, it is very difficult to lose, especially if you regularly push your database to another repository.Git has three main states that your files can reside: modified, staged, and committed.Modified means that you have changed the file but have not committed it to your database yet.Staged means that you have marked a modified file in its current version to go into your next commit snapshot.Committed means that the data is stored in your local database.In simple terms, Git has three main parts: the working tree, the staging area, and the Git directory.The working tree is the current version of the project that you are working on. It contains all the files you need to use or modify.The staging area is a file that contains information about what changes you want to include in your next commit. You can selectively stage changes, which means you can choose which changes you want to commit and which ones you don't.The Git directory is where Git stores all the information about your project, including the history of changes and the current state of the project. When you clone a repository from another computer, you are copying the Git directory.The basic Git workflow involves making changes to your working tree, selectively staging the changes you want to include in your next commit, and then committing those changes to the Git directory.Enough with the boring stuff! Now that we've covered the basics of Git, it's time to take the next step and start using Git.The easiest way to Install Git on your system is through the command line. Let's open a terminal. If you are working on Ubuntu or Debian, all you need to do is run the following command.For Ubuntu, this PPA provides the latest stable upstream Git versionIf you are using a different Linux distro, you can find instructions on the Official Downloads Page.To install git on windows, all you need to do is follow these steps.Go to the Git website at https://git-scm.com/download/winClick the download button for the 64-bit Git for Windows SetupOnce the download is complete, double-click on the downloaded file to start the installation processSelect the desired language for the installer and click 'OK'Follow the on-screen instructions to complete the installationTo verify the installation, you can do any of the following:Go to any folder or the desktop and right-click, if you see "Git Bash Here", then you successfully installed Git on your machine.Open a Command Line or Powershell, and type:If you see something like this: git version 2.39.1.windows.1, then you successfully installed Git on your machine.There are several ways to install Git on a Mac. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run git from the Terminal the very first time.If you don’t have it installed already, it will prompt you to install it.Or you can follow the following steps:Go to the Git website at https://git-scm.com/download/macClick the download button for the macOS installerOnce the download is complete, double-click on the downloaded file to start the installation processFollow the on-screen instructions to complete the installationOpen the Terminal app and type git --version in the terminal window and press enter to verify that Git is installed correctly. If you see the Git version information, it means Git has been successfully installed.That's it! You now have Git installed on your machine and you're ready to start using it.In this post, We've explained what Git is, how it works, and its advantages. We've also explored the three main states your files can reside in and provided installation guides for Linux, Windows, and macOS. I hope this post has been helpful to you, and I welcome your feedback in the comments. In the next post, we will dive deeper into Git's basic commands and help you create your first repository. So, stay tuned!Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Imam Ali Mustofa - Jul 26 Nayan Pahuja - Jul 26 IagoLast - Jul 26 Dsysd Dev - Jul 26 Once suspended, Moharamfatema will not be able to comment or publish posts until their suspension is removed. Once unsuspended, moharamfatema will be able to comment and publish posts again. Once unpublished, all posts by moharamfatema will become hidden and only accessible to themselves. If moharamfatema is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Fatema Moharam. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag moharamfatema: moharamfatema consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging moharamfatema will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Git: The Basics

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×