💾 Archived View for darknesscode.xyz › notes › git-branches.gmi captured on 2023-07-22 at 16:23:10. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-05)
-=-=-=-=-=-=-
Listing all branches with "git branch" command
git branch -a
Switching to a existing branch with "git checkout" command
git checkout <existing_branch>
Create and switch to a new branch with "git checkout -b" command
git checkout -b <new_branch>
Switch to a non-existing branch, the following error message will show up
error: pathspec 'non-existing-branch' did not match any file(s) known to git To solve this error, you will have to append the “-b” (for “new branch”) option to the checkout command.
A quick way of switching branch on Git is to use the “git switch” command and specify the name of the branch you want to switch to.
git switch <existing_branch>
Create and switch to a new branch with "git switch -c" command
$ git switch -c <new_branch>
Switch to a non-existing branch, the following error message will show up
fatal: invalid reference: non-existing-branch To solve this error, make sure to append the “-c” option to the “git switch” command to specify that you want to switch to a new branch.
First commit all your changes in your branch like your normally do, like
git status git add –a git commit –m "Some commit message"
Then switch to the master branch
git checkout master
Check that you are in the master branch, now run "git merge" command
git merge <branch>
If all goes well then our job is done. The new feature commits now appear in the master branch.
To delete a local branch with "git branch -d" command
git branch -d <branch>
----------
----------
© DarknessCode