Branches allow you to work on different features or fixes separately from the main codebase. In this guide, you will learn how to create branches, switch between them, and merge changes.
To create a new branch:
git checkout -b <branch-name>
This command creates a new branch and switches to it.
To list all branches in your repository:
git branch
The current branch will be highlighted with an asterisk (*).
To switch to another branch:
git checkout <branch-name>
When you're ready to bring changes from one branch into another (typically the main branch):
git checkout main
git merge <branch-name>
If Git cannot automatically merge the changes, you'll need to resolve conflicts manually:
git add <file>
git commit -m "Resolve merge conflicts"
Once you've successfully merged a branch, you can delete it:
git branch -d <branch-name>
If the branch hasn't been merged yet and you still want to delete it, use:
git branch -D <branch-name>
Branching and merging allow you to isolate work and integrate it efficiently into the main project, enhancing collaboration.
- PT-BR
Branches permitem que você trabalhe em diferentes funcionalidades ou correções separadamente do código principal. Neste guia, você aprenderá a criar branches, alternar entre eles e mesclar mudanças.
Para criar um novo branch:
git checkout -b <nome-do-branch>
Esse comando cria um novo branch e muda para ele.
Para listar todos os branches no seu repositório:
git branch
O branch atual será destacado com um asterisco (*).
Para alternar para outro branch:
git checkout <nome-do-branch>
Quando estiver pronto para trazer as mudanças de um branch para outro (geralmente o branch main):
git checkout main
git merge <nome-do-branch>
Se o Git não conseguir mesclar as mudanças automaticamente, você precisará resolver os conflitos manualmente:
git add <arquivo>
git commit -m "Resolve conflitos de merge"
Após mesclar um branch com sucesso, você pode deletá-lo:
git branch -d <nome-do-branch>
Se o branch ainda não foi mesclado e você deseja deletá-lo mesmo assim, use:
git branch -D <nome-do-branch>
Branching e merging permitem isolar o trabalho e integrá-lo de forma eficiente ao projeto principal, facilitando a colaboração.