Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Git is a distributed version control system widely used for source code management. It allows multiple developers to work on a project simultaneously without interfering with each other's work. One of the key features of Git is branching, which allows you to diverge from the main line of development and continue to do work without affecting that main line. This article will guide you through managing Git branches on macOS, commonly known as the Apple environment.
Examples:
Creating a New Branch:
To create a new branch in Git, you can use the git branch
command followed by the name of the branch you want to create. Here's how you can do it on macOS:
git branch new-feature
This command creates a new branch named new-feature
from the current branch.
Switching to a Branch:
To start working on a different branch, you need to switch to it using the git checkout
command:
git checkout new-feature
Alternatively, you can create and switch to a new branch in one command using git checkout -b
:
git checkout -b another-feature
Listing All Branches:
To see all branches in your repository, use the git branch
command without any arguments:
git branch
This will list all the branches and highlight the current branch with an asterisk (*).
Merging Branches:
Once you have completed work on a branch, you might want to merge it back into the main branch (often main
or master
). First, switch to the branch you want to merge into:
git checkout main
Then, use the git merge
command:
git merge new-feature
Deleting a Branch:
After a branch has been merged and is no longer needed, you can delete it using the git branch -d
command:
git branch -d new-feature
If the branch has not been merged, and you still want to delete it, use the -D
option:
git branch -D new-feature
These commands can be executed in the Terminal application on macOS, which provides a command-line interface to interact with Git.