Most individuals working in the tech world in some form must know the basics of Git. Git is the likely candidate for most popular version control system, and more and more workflows — from coding to writing documentation, or even managing “dotfiles” at your dedicated server host — integrate some form of Git version control. But Git can be intimidating to newcomers because of the unique terminology — Git is almost like its own language. This article will introduce you to the critical concepts so you can get up and running right away.
While this article introduces the main concepts behind Git, you are best advised to follow it up with our complete Git getting started guide which, in addition to conceptual information, provides the actual Git commands you will run live.
Adding Files To The Staging Index
Git basically manages changes you make to one or more files. That’s about it. Once you have initialized a project directory (“working directory,” in Git terms) you tell Git which files to track for changes. You do this by “adding” files to a “staging index.” The staging index is basically a list of changes: files changed, files added, or files deleted.
Commit Your Current State
The “commit” action puts the state of your tracked files and project into the permanent record. The commit process takes the changes, additions, and deletions in your staging index and packages them into the contents of the commit.
Git allows you to try out changes or iterate on different ideas using branches. A branch allows you to literally split the project and then integrate your changes later. You can also send branches up to your remote repository so that other users can pull them down, try out your changes, and then commit new code on that same branch. If all the changes work well, you can integrate the changes on the divergent branch into the “master” branch.
But, as with everything else in Git, branching is a general purpose tool with all sorts of different use cases. So you are encouraged to get creative with it. The branch is yet another reference point in Git, which references the state of your code at a certain time. Just like commits, a branch can be used as a marker or reference point. But unlike commits, a branch can be merged into another branch.
Reset (With Caution)
The Git reset command will bring your current project state to a different state. You might find a few cases in which you made changes but want to revert to what you had before, or you might want to rewind the project back to a few commits behind. The reset command can help you do that.
In most cases, you will want to do a hard reset. But you should use caution, because the hard reset will also wipe out changes you might currently have in your working directory or staging index. Familiarize yourself with the different types of resets: soft, hard, and mixed.
VPS vs cloud hosting? Which one is right for you?