
- Git - Home
- Git - Version Control
- Git - Basic Concepts
- Git - Command Line
- Git - Installation
- Git - First Time Setup
- Git - Basic Commands
- Git - Getting Help
- Git - Tools
- Git - Cheat Sheet
- Git - Terminology
- Git - Life Cycle
- Git - Get a Repository
- Git - Adding New Files
- Git - Recording Changes
- Git - Viewing Commit History
- Git Branching
- Git - Branches in a Nutshell
- Git - Creating a New Branch
- Git - Switching Branches
- Git - Branching and Merging
- Git - Merge Conflicts
- Git - Managing Branches
- Git - Branching Workflows
- Git - Remote Branches
- Git - Tracking Branches
- Git - Rebasing
- Git - Rebase vs. Merge
- Git - Squash Commits
- Git Operations
- Git - Clone Operation
- Git - Tagging Operation
- Git - Aliases Operation
- Git - Commit Operation
- Git - Stash Operation
- Git - Move Operation
- Git - Rename Operation
- Git - Push Operation
- Git - Pull Operation
- Git - Fork Operation
- Git - Patch Operation
- Git - Diff Operation
- Git - Status Operation
- Git - Log Operation
- Git - Head Operation
- Git - Origin Master
- Git Undoing
- Git - Undoing Changes
- Git - Checkout
- Git - Revert
- Git - Reset
- Git - Restore Operation
- Git - Rm
- Git - Switch Operation
- Git - Cherry-pick
- Git - Amend
- Git on the Server
- Git - Local Protocol
- Git - Smart HTTP Protocol
- Git - Dumb HTTP Protocol
- Git - The SSH Protocol
- Git - The Git Protocol
- Git - Getting Git on a Server
- Git - Setting up the Server
- Git - Daemon
- Git - GitWeb
- Git - GitLab
- Git - Third Party Hosted Options
- Distributed Git
- Git - Distributed Workflows
- Git - Contributing to a Project
- Git - Maintaining a Project
- Customizing Git
- Git - Configuration
- Git - Hooks
- Git - Attributes
- Git - Init
- Git - Commit
Git - Terminology
Understanding Git terminology is crucial for effectively using Git as a version control system. Heres a detailed exploration of essential Git terminology, including definitions and explanations of key concepts and commands.
Git repository
A repository, or repo, is the fundamental unit in Git where all the project files and their revision history are stored. There are two types of repositories:
Git uses a system of organized storage called a repository to handle the files and history of a project.
Local Repository: This is the version of the repository on your local machine. It includes the working directory, staging area, and the .git directory containing the actual version history.
Remote Repository: This is the version of the repository hosted on a server or a cloud service like GitHub, GitLab, or Bitbucket. Remote repositories allow multiple developers to collaborate on the same project.
Working directory
The working directory is where you perform your actual work. All of the files that Git tracks are kept in a working directory.
Git keeps an eye on these files and gets them ready for commits.
In essence, it acts as the working area where modifications are performed prior to being completed and committed to the Git repository.
Staging Area (Index)
The staging area, also known as the index, is a space where you can prepare a snapshot of your changes before committing them to the repository. When you use >git add, changes are moved to the staging area. This allows you to control which changes are included in the next commit.
Commit
A commit is a snapshot of your project at a specific point in time. It records changes to the repository and includes a commit message that describes the changes made. Each commit is identified by a unique hash (SHA-1 checksum). The command git commit creates a new commit from the changes in the staging area.
Branch
A branch in Git is a separate development path that departs from the main project.
It permits working independently on project features or versions.
Creating, renaming, listing, and deleting branches are important operations.
Branches allow for efficient version control and collaboration by allowing them to be pulled or pushed to remote repositories and then merged into the main project.
Branches are managed with commands like git branch, git checkout, and git merge .
Merge
Merging is the process of integrating changes from one branch into another. When you merge a branch into another branch, Git combines the changes from both branches. The command git merge is used to perform this operation. Merges can be straightforward or may require resolving conflicts if changes overlap.
Rebase
Rebasing is an alternative to merging that integrates changes from one branch onto another by replaying commits. The git rebase command applies commits from one branch onto another, creating a linear history. Rebasing can simplify the commit history but should be used carefully, especially with shared branches.
Commit History
The commit history is a chronological list of all commits made in a repository. Each commit in the history is identified by a unique hash and includes metadata like the author, date, and commit message. The command git log displays the commit history, allowing you to review past changes.
Tag
A tag is a reference to a specific commit that is used to mark important points in the repositorys history, such as releases or milestones. Tags can be lightweight (simple pointers) or annotated (contain additional metadata). The command git tag is used to create and manage tags.
Remote
A remote is a version of your repository hosted on a server or cloud service. It allows collaboration with others by providing a centralized location for sharing changes. Common commands for working with remotes include git remote, git fetch, git pull, and git push .
Push
To upload changes from a local repository to a remote repository in Git, use the git push command.
Commits from the local branch can be moved to a designated branch in the remote repository by using the git push command.
Usually, the command takes as inputs the name of the branch and the repository.
Pushing should be done carefully since it has the potential to overwrite changes made in the remote repository.
Pull
To fetch and integrate changes from a remote repository into the local repository using Git, use the git pull command.
Updates are retrieved from the remote server and merged into your current working branch using the git pull command.
A pull request is also how team members are informed when changes in a feature branch are prepared for review.
The code is reviewed and merged into the main branch after the developer sends a pull request via a remote service like GitHub.
Fetch
The git fetch command retrieves updates from a remote repository without merging them into your local branch. It downloads new commits, branches, and tags but does not alter your working directory. Fetching is useful for reviewing changes before integrating them.
It can be used with arguments like git fetch --all to fetch updates from all branches of a repository and updates remote-tracking branches.
Before choosing to merge updates into your local repository, one can use this command to view changes from the remote repository.
Conflict
A conflict occurs when Git cannot automatically merge changes from different branches because they overlap or contradict each other. Conflicts require manual resolution by editing the affected files and then staging the resolved changes. Conflicts are indicated in files with conflict markers and can be resolved using tools or editors.
HEAD
The symbolic reference HEAD in Git refers to the active branch or commit.
It is the most recent commit in the branch that is currently being checked out.
By using commands such as git checkout to switch branches, HEAD is updated to point to the new branch's tip, which reflects the branch's most recent commit.
Checkout
Git allows users to navigate between multiple branches or versions within a repository by using the git checkout command.
To switch to a particular branch, such as the main or beta branch, use git checkout branch-name.
This enables you to transition between different development branches, such as going from a stable branch to a beta version and back again.
Clone
An individual can make a local copy of a remote repository by using the git clone command.
The complete repository, including files and history, can be copied to your local computer by running git clone repo, where "repo" is the repository address.
To obtain a local version of a repository from a platform such as GitHub, we must use this command.
Fork
A clone of a repository hosted on a remote server called a Git fork lets users freely experiment and make changes to the repository without having an impact on the original project.
Usually, developers fork a repository so they may independently check for and fix updates.
You can suggest merging your adjustments back into the original repository by submitting a pull request after making updates, such as bug fixes.
This process maintains the integrity of the primary project while facilitating contributions and bug fixes.
Status
The git status command in Git gives a summary of the local repository's current state.
Users can view details about untracked files, staged changes, and the staging area by using git status.
It is useful for recording modifications that have been done or that still need to be committed, as well as for knowing the working tree status.
DIFF
The git diff command is a flexible tool used to show differences between files or commits.
Changes between the index and HEAD, between commits, and between the working directory and the index (staging area) can all be shown.
In essence, git diff shows the changes that have been made and the modifications that are ready to be committed.
Reset
The git reset command is used to undo changes by adjusting the state of the repository.
The working directory, index (staging area), and HEAD can all be reset.
git reset can take three primary forms:
Soft Reset: Maintains changes in the working directory and index by moving HEAD to a prior commit.
Mixed Reset: Maintains changes in the working directory while moving HEAD and updating the index.
Hard Reset: Deletes all modifications and resets HEAD, the index, and the working directory to a prior commit.
Stash
To temporarily store uncommitted changes in the working directory, use the git stash command in Git.
As a result, users can work on several projects or swap branches without committing to finished work.
Applying the stored modifications back to the working directory allows us to pick up where we left off when you're ready.
This is useful for managing work-in-progress without cluttering the commit history.
Revert
The git revert command in Git is used for creating a fresh commit that reverses the changes from the previous commit.
It is similar to the undo command in that it adds a new commit that undoes the changes made by the specified commit, rather than deleting history.
This method successfully reverses modifications while preserving the project's history.
Submodule
A submodule is a repository embedded within another repository. It allows you to include and manage external repositories as part of your project. Submodules are managed using commands like git submodule add, git submodule update, and git submodule sync.
Blame
The git blame command shows who last modified each line of a file. It is useful for tracking down changes and understanding the history of specific lines. Blame output includes commit hashes, author names, and dates for each line.
Cherry-pick
Applying particular commits from one branch to another without merging the branch as a whole is possible with Git's git cherry-pick command.
To choose and apply specific changes from one branch, such as a beta branch, to another branch, such as the main project branch, use git cherry-pick commit-id.
This helps to transfer specific modifications or correct errors without affecting other commits made in the branch.
Index
The staging area, also called the Git index, acts as a bridge between the repository and the working directory.
It is used to prepare and organize changes before committing them.
The files are added to the index when you add them to the staging area.
As soon as you commit, the repository records the index modifications and updates the HEAD to reflect the new commit.
Master
The master or main branch in Git is the main branch used for development and is the default branch in a repository.
The first branch you usually get when you clone a repository is called master (or main, since many repositories now use this term to be more inclusive).
The development of the project revolves around this branch, which is frequently used to maintain reliable, production-ready code.
Origin
In Git, origin is a shorthand alias for the URL of the remote repository from which a project was cloned.
It simplifies referencing the remote repository by providing a local alias instead of using the full URL.
This makes it easier to perform operations like fetching, pushing, and pulling changes from the remote repository.
.gitignore
The .gitignore file in Git indicates which files or directories Git should not add to the staging region and instead ignore.
It doesn't impact files that Git is currently tracking; it only applies to untracked files.
This helps in controlling the files that are added to the repository.
Squash
Squash in Git describes the process of combining several commits into a single commit.
Usually, the interactive rebase command is used for this.
Squashing helps to organize similar changes into a single, more manageable branch before combining them into the main branch.
The procedure involves combining changes from many commits into a single file that is subsequently added to the index.
git rm
To delete files from the working directory, repository, and Git index, use the git rm command.
It ensures that tracked files are erased from the working directory as well as the staging area.
When it comes to removing files from version control or files that are no longer needed, this command is quite effective.