Git Terminology
Git is a distributed version control system that helps developers manage changes to source code over time. Understanding Git terminology is essential for effectively using Git. Here’s a breakdown of key Git terms:
1. Repository
A repository (or repo) is a directory or storage space where your project resides. It contains all the project files, including the entire history of changes made to those files.
Creating a Repository
To create a new repository:
git init my-repo
cd my-repo
2. Clone
Cloning a repository means creating a copy of a remote repository on your local machine.
Cloning a Repository
git clone https://github.com/user/repo.git
3. Commit
A commit is a snapshot of changes in the repository. It is a fundamental unit of change in Git, capturing the state of the repository at a particular point in time.
Making a Commit
git add .
git commit -m "Initial commit"
4. Branch
A branch is a parallel version of a repository. It allows you to work on different features or fixes independently of the main codebase (usually the master or main branch).
Creating and Switching Branches
git branch new-feature
git checkout new-feature
5. Merge
Merging is the process of integrating changes from one branch into another. This is commonly done when you want to incorporate new features or bug fixes into the main branch.
Merging Branches
git checkout main
git merge new-feature
6. Pull Request
A pull request (PR) is a way to propose changes to a repository. It allows other developers to review your changes before they are merged into the main branch.
Creating a Pull Request
- Push your branch to the remote repository:
git push origin new-feature
- Go to the repository on GitHub and create a pull request.
7. Remote
A remote is a version of your repository hosted on the internet or another network. It allows you to collaborate with others.
Adding a Remote
git remote add origin https://github.com/user/repo.git
8. Push
Pushing is the process of uploading your local changes to a remote repository.
Pushing Changes
git push origin main
9. Pull
Pulling is the process of fetching and merging changes from a remote repository into your local repository.
Pulling Changes
git pull origin main
10. Fetch
Fetching is the process of downloading commits, files, and references from a remote repository into your local repository without merging.
Fetching Changes
git fetch origin
11. Stash
Stashing is a way to temporarily save changes you have made to your working directory without committing them.
Stashing Changes
git stash
Applying Stashed Changes
git stash apply
12. Status
The git status command displays the state of the working directory and the staging area. It shows which changes have been staged, which haven't, and which files aren't being tracked by Git.
Checking Status
git status
13. Log
The git log command shows the commit history for the repository.
Viewing Commit History
git log
14. Diff
The git diff command shows the differences between files or commits.
Viewing Differences
git diff
15. Rebase
Rebasing is the process of moving or combining a sequence of commits to a new base commit. It is often used to clean up the commit history.
Rebasing a Branch
git checkout new-feature
git rebase main
16. Tag
A tag is a reference to a specific commit. It is typically used to mark release points (e.g., v1.0, v2.0).
Creating a Tag
git tag v1.0
Pushing Tags
git push origin v1.0
Understanding these Git terms and commands is crucial for effective version control. Each term and command plays a vital role in managing changes and collaborating with other developers. By mastering these concepts, you can leverage Git to its full potential, ensuring a smooth and efficient development workflow.