[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Pulling and rebasing ] | [ Up : Basic Git procedures ] | [ Creating and removing branches > ] |
2.3.3 Using local branches
Creating and removing branches | ||
Listing branches and remotes | ||
Checking out branches | ||
Merging branches |
[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Using local branches ] | [ Up : Using local branches ] | [ Listing branches and remotes > ] |
Creating and removing branches
Local branches are useful when you’re working on several different projects concurrently. To create a new branch, enter:
git branch name
To delete a branch, enter:
git branch -d name
Git will ask you for confirmation if it sees that data would be
lost by deleting the branch. Use -D
instead of -d
to bypass this. Note that you cannot delete a branch if it is
currently checked out.
[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Creating and removing branches ] | [ Up : Using local branches ] | [ Checking out branches > ] |
Listing branches and remotes
You can get the exact path or URL of all remote branches by running:
git remote -v
To list Git branches on your local repositories, run
git branch # list local branches only git branch -r # list remote branches git branch -a # list all branches
[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Listing branches and remotes ] | [ Up : Using local branches ] | [ Merging branches > ] |
Checking out branches
To know the currently checked out branch, i.e. the branch whose source files are present in your working tree, read the first line of the output of
git status
The currently checked out branch is also marked with an asterisk
in the output of git branch
.
You can check out another branch other_branch
, i.e.
check out other_branch
to the working tree, by
running
git checkout other_branch
Note that it is possible to check out another branch while having
uncommitted changes, but it is not recommended unless you know
what you are doing; it is recommended to run git status
to check this kind of issue before checking out another branch.
[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Checking out branches ] | [ Up : Using local branches ] | [ Commits and patches > ] |
Merging branches
To merge branch foo
into branch bar
,
i.e. to “add” all changes made in branch foo
to
branch bar
, run
git checkout bar git merge foo
If any conflict happens, see Resolving conflicts.
There are common usage cases for merging: as a translator, you
will often want to merge master
into
lilypond/translation
; on the other hand, the Translations
meister wants to merge lilypond/translation
into
master
whenever he has checked that
lilypond/translation
builds successfully.
[ << Working with source code ] | [Top][Contents][Index][ ? ] | [ Compiling >> ] | ||
[ < Checking out branches ] | [ Up : Using local branches ] | [ Commits and patches > ] |