Git Terminology Explained
Posted on June 7, 2024 • 7 min read • 1,431 wordsUnderstand essential Git terminology to master version control and collaborate effectively.
Before diving into the commands and workflows in Git, it’s important to understand the terminology used in version control. This glossary will help you become familiar with key concepts and terms through examples from a “Note Taking App” project.
Imagine you are working on a simple “Note Taking App” project. This app allows users to create, edit, and delete notes. As you develop this project, you’ll encounter various Git concepts and commands. Let’s explore these terms with relevant examples from this project.
A storage space where your project files and their version history are kept. It can be local (on your machine) or remote (on a server). For your “Note Taking App,” you create a repository named note-taking-app
to store all the code and assets.
Creating a copy of an existing repository. This is usually done to start working on an existing project. You clone the note-taking-app
repository from GitHub to your local machine to start contributing.
git clone https://github.com/username/note-taking-app.git
A snapshot of your project at a specific point in time. Each commit records changes to your files and includes a message describing the changes. After adding a new feature to allow users to tag their notes, you commit the changes with a descriptive message.
git commit -m "Added tagging feature for notes"
A parallel version of your repository. Use branches to develop features, fix bugs, or safely experiment. The default branch name in Git is main
or master
. You create a new branch feature/tagging
to develop the tagging feature without affecting the main codebase.
git checkout -b feature/tagging
Switching between branches or commits. It updates the working directory to match the specified branch or commit. After completing the tagging feature, you switch back to the main branch to start working on another task.
git checkout main
Combining changes from one branch into another. This is used to integrate feature branches back into the main development line. Once the tagging feature is tested and reviewed, you merge it into the main branch.
git checkout main
git merge feature/tagging
Reapplying commits on top of another base tip, creating a linear history. This is often used to keep a clean project history. To keep your feature branch up to date with the main branch, you rebase it.
git checkout feature/tagging
git rebase main
A space where changes are prepared before committing them. You can add files to the staging area using git add
. You modify several files to implement the tagging feature and add them to the staging area before committing.
git add .
A common repository on a server that all team members use to exchange their changes. Examples include GitHub, GitLab, and Bitbucket. The note-taking-app
repository hosted on GitHub acts as the remote repository for all team members.
Fetching changes from a remote repository and merging them into your local repository. It’s a combination of git fetch
and git merge
. Before starting your day’s work, you pull the latest changes from the remote repository to ensure your local copy is up to date.
git pull origin main
Sending your commits to a remote repository. This updates the remote repository with your changes. After committing your changes locally, you push them to the remote repository so others can access them.
git push origin feature/tagging
Temporarily saving changes that are not yet ready to be committed. This allows you to switch branches without committing incomplete work. You need to switch branches to fix a critical bug, but you have unfinished changes. You stash them first.
git stash
The current commit your working directory is based on. Typically, it points to the latest commit on your current branch. HEAD points to the latest commit on the feature/tagging
branch you are currently working on.
A specific point in history that is important (usually a release). Tags are often used to mark release versions like v1.0.0
. After completing the first version of your note-taking app, you tag this point in the repository.
git tag v1.0.0
Downloading changes from a remote repository without integrating them into your working directory. This is useful for updating your view of the remote repository. You fetch the latest updates from the remote repository to see what changes have been made by others.
git fetch origin
The default name for a remote repository in Git. It’s the repository from which you cloned your project and where you typically push your changes. origin
refers to the remote repository of your note-taking-app
on GitHub.
Occurs when changes in different branches interfere with each other. Git requires you to resolve these conflicts manually. You and another developer make conflicting changes to the same file in different branches, and Git flags this during a merge.
Shows the differences between commits, branches, or your working directory. This helps you understand what has changed in the code. Before committing, you use git diff
to review the changes you made to the tagging feature.
git diff
A Git command that shows who last modified each line of a file. Useful for tracking down the origin of changes. To find out who introduced a bug in the note-taking-app
, you use git blame
.
git blame filename
Scripts that Git automatically executes before or after certain events, like committing or merging. Hooks are used to enforce policies or automate tasks. You set up a pre-commit hook to run tests before allowing a commit.
# Example of setting up a pre-commit hook
echo "npm test" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
A mechanism to keep track of updates to the tip of branches and other references. It helps you recover from changes that you made in Git. After a rebase goes wrong, you use git reflog
to find the previous state and recover your work.
git reflog
A repository embedded inside another repository. Useful for including and tracking third-party code or dependencies. You add a third-party library as a submodule to your note-taking-app
repository.
git submodule add https://github.com/user/library.git
A copy of a repository that allows you to freely experiment with changes without affecting the original project. You fork an open-source project to make some changes and improvements, then submit a pull request to contribute back to the original project.
A method of submitting contributions to a project. You create a pull request to propose changes you’ve made in your fork or branch to be merged into the original repository. This is a common practice in collaborative projects.
Applying the changes from a specific commit to your current branch. This allows you to selectively apply changes without merging the entire branch.
git cherry-pick commit-hash
Combining multiple commits into a single commit. This is useful for cleaning up a branch before merging it into the main branch.
git rebase -i HEAD~n
Modifying the most recent commit. This is useful for making corrections to the last commit message or content.
git commit --amend
Marking a specific point in the commit history as important. This is often used to create version numbers for releases.
git tag -a v1.0.0 -m "Initial release of Note Taking App"
A state where your HEAD is not pointing to a branch but to a specific commit. This can happen when you check out an older commit.
git checkout commit-hash
A type of merge where the branch pointer is simply moved forward to point to the latest commit of the merged branch. This can only happen if there are no diverging commits.
git merge --ff-only branch-name
A branching model for Git, proposed by Vincent Driessen, that defines a strict branching model designed around the project release.
# Example of initializing git flow
git flow init
A file that contains differences between two versions of a file or a set of files. You can create and apply patches to manage changes across different environments or collaborators.
# Create a patch
git diff > changes.patch
# Apply a patch
git apply changes.patch
Creating a new commit that undoes changes from a specific commit. This is useful for safely undoing changes.
git revert commit-hash
Understanding these terms will make it easier to follow along with the commands and concepts discussed in the series. Keep this glossary handy as a reference!