Local and Remote Branches in Git
Local Branch
A local branch is a branch that exists in your local Git repository. You create and manage local branches on your machine, and they are used to track your work and changes.
- Creating a Local Branch:
git checkout -b my-feature-branch
- This command creates a new branch called
my-feature-branch
and switches to it. - Listing Local Branches:
git branch
This command lists all the branches in your local repository.
Remote Branch
A remote branch is a branch that exists on a remote repository, such as GitHub, GitLab, or Bitbucket. Remote branches are used to share your work with others and collaborate on a project.
- Fetching Remote Branches:
git fetch
- This command updates your local copy of the remote branches without modifying your local branches.
- Listing Remote Branches:
git branch -r
- This command lists all the remote branches that you have fetched.
- Tracking Remote Branches:
git checkout --track origin/my-feature-branch
This command creates a local branch that tracks the remote branch origin/my-feature-branch
.