Git
What is Git?
Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It allows multiple people to work on the same project simultaneously, without interfering with each other's work.
Key Concepts:
Repository (Repo):
- A repository is like a project folder that contains all the files, folders, and version history of your project.
- It can be local (on your computer) or remote (on a server like GitHub, GitLab, Bitbucket, etc.).
Commit:
- A commit is a snapshot of your repository at a specific point in time.
- It includes changes you've made to files and a message describing those changes.
- Commits are used to track the history of your project and are essential for collaboration.
Branch:
- A branch is a parallel version of your repository.
- It allows you to work on new features or fixes without affecting the main codebase (usually the
masterbranch). - Branches are lightweight and easy to create, merge, or delete.
Merge:
- Merging combines changes from different branches into one.
- It's often used to incorporate new features or bug fixes into the main codebase.
Pull Request (PR):
- A pull request is a request to merge changes from one branch into another (usually from a feature branch into the
masterbranch). - It allows collaborators to review the changes, discuss them, and suggest improvements before merging.
- A pull request is a request to merge changes from one branch into another (usually from a feature branch into the
Remote:
- A remote is a version of your repository hosted on a server.
- It serves as a central location for collaboration and backup.
- Popular remote repository hosting services include GitHub, GitLab, and Bitbucket.
Basic Git Workflow:
Initialize a Repository:
- To start tracking a project with Git, you initialize a repository in the project directory using the
git initcommand.
- To start tracking a project with Git, you initialize a repository in the project directory using the
Add and Commit Changes:
- After making changes to your files, you add them to the staging area using
git add. - Once you're satisfied with the changes, you commit them to the repository using
git commit -m "Commit message".
- After making changes to your files, you add them to the staging area using
Create and Manage Branches:
- You create a new branch using
git checkout -b branch_name. - Switch between branches using
git checkout branch_name. - List branches with
git branch. - Delete branches with
git branch -d branch_name.
- You create a new branch using
Merge Changes:
- Merge changes from one branch into another using
git merge branch_name.
- Merge changes from one branch into another using
Collaborate with Remotes:
- Add a remote repository with
git remote add remote_name remote_url. - Push changes to a remote repository with
git push remote_name branch_name. - Pull changes from a remote repository with
git pull remote_name branch_name. - Clone a remote repository to your local machine with
git clone remote_url.
- Add a remote repository with
Review and Merge Pull Requests:
- Create a pull request on a remote repository's website.
- Review pull requests, leave comments, and discuss changes with collaborators.
- Merge approved pull requests into the main branch.
Learning Resources:
- Official Git Documentation: Git SCM
Comments
Post a Comment