What is it, who made it and why is git important in the tech world?
Simply put, git is a content management and tracking system that allows you to track, share, and reconcile changes to document over time. Git includes directories that continuously change as code is added throughout application or website development.
Git was developed by Linus Torvalds, the creator of Linux. He gave it the name “GIT” when he wrote the very first version where he described the tool as “the stupid content tracker” and the name as a random three-letter combination that is pronounceable, and not actually used by any common UNIX command.
To really understand how git works, you need to familiarize yourself with the basic vocabulary.
- Commit: a “packet” of changes
- Branch: a particular history of commits
- Tree-ish: anyway to refer to a specific commit
The “commit” command captures a snapshot of the project’s currently staged changes. They track deltas, which are changes to your documents since the last commit. Committed snapshots can be thought of as “safe” versions of a project. Git will never change them unless you explicitly ask it to. A commit is comprised of these important features:
- Hast (Tree-Ish)
- Parent Commit
A branch represents an independent line of development. Branches serve as an abstraction for the edit-stage-commit process. Think of them as a way to request a brand-new working directory, staging area, and project history.
- Branches track a divergent history of commits
- Each commit can only have one parent, but many children
- Each branch has a name, a Tree-ish which
refers to the tip (most recent commit)
Tree-ish’s are different labels for referring to a particular commit. There are different types of labels but they are all equally valid for referring to a commit. Some examples of Tree-ish’s include:
- “HEAD” is a Tree-ish which refers to the currently selected commit
- “HEAD” is like the needle on a record player
- Tags are a Tree-ish to give commits a more friendly/useful name
- Most commonly used for version numbers
- Tags can be anything
- Commit hashes
Now that we have the basics covered, let’s get into Remotes, Push and Pull, Merging and Rebasing.
A remote in git is a common repository that all team members use to exchange their changes. In most cases, such a remote repository is stored on a code hosting service like GitHub or on an internal server.
- Remotes are servers which maintain copies of your git repositories.
- Sync local changes up to remote, and remote changes down to local.
- You can have multiple remotes.
- Remote branches/tags are prefixed with the remote name.
Push and Pull.
Git pull is one of many commands that claim the responsibility of ‘syncing’ remote content. The git remote command is used to specify what remote endpoints the syncing commands will operate on. The git push command is used to upload content to a remote repository.
- “Git push” to sync changes up to the Remote.
- “Git pull” to sync changes down from the Remote.
- When pushing, new branches must be created upstream on Remote with “git push –set upstream <remote> <branch>”.
Merging is git’s way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
- “Git merge” reconciles two divergent branches that share a common ancestor.
- Changes from the source are applied on top of the target.
From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you’d created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.
- “Git rebase” also reconciles two divergent branches that share a common ancestor.
- Changes from the target are applied on top of the source.
To recap, git is the most commonly used version control system. It tracks the changes you make to files, so you have a record of what has been done, and you can revert to specific versions should you ever need to. Git also makes collaboration easier, allowing changes by multiple people to all be merged into one source. For more helpful tips and insight to strengthen your development knowledge, visit us at www.TyrannosaurusTech.com.