Questions tagged [git-branch]

git-branch is the Git command that manages branches.

git branch is the command that manages branches within a Git repository.

The default branch is called master.

To create a new branch:

git branch <branch-name>

To see a list of all branches in the current repository:

git branch

Switching to another branch:

git checkout <branch-name>

Creating a new branch and switch to it in one step:

git checkout -b <branch-name>

Deleting a branch:

git branch -d <branch-name>

Create a branch with the changes from the current branch:

git stash
git stash branch <branch-name>

More information on git-branch manual page.

3220 questions
41 answers

How do I delete a Git branch locally and remotely?

Failed Attempts to Delete a Remote Branch: $ git branch -d remotes/origin/bugfix error: branch 'remotes/origin/bugfix' not found. $ git branch -d origin/bugfix error: branch 'origin/bugfix' not found. $ git branch -rd origin/bugfix Deleted remote…
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
39 answers

How do I rename a local Git branch?

How do I rename a local branch which has not yet been pushed to a remote repository? Related: Rename master branch for both local and remote Git repositories How do I rename both a Git local and remote branch name?
  • 122,703
  • 20
  • 73
  • 107
41 answers

How do I remove local (untracked) files from the current Git working tree?

How do I delete untracked local files from the current working tree?
  • 343,444
  • 107
  • 203
  • 205
22 answers

Move the most recent commit(s) to a new branch with Git

How do I move my recent commits on master to a new branch, and reset master to before those commits were made? e.g. From this: master A - B - C - D - E To this: newbranch C - D - E / master A - B
Mark A. Nicolosi
  • 82,413
  • 11
  • 44
  • 46
18 answers

How do I push a new local branch to a remote Git repository and track it too?

How do I: Create a local branch from another branch (via git branch or git checkout -b). Push the local branch to the remote repository (i.e. publish), but make it trackable so that git pull and git push will work.
Roni Yaniv
  • 57,651
  • 5
  • 19
  • 16
48 answers

How do I clone all remote branches?

My master and development branches are tracked remotely on GitHub. How do I clone both these branches?
Peter Coulton
  • 54,789
  • 12
  • 54
  • 72
23 answers

Make an existing Git branch track a remote branch?

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch? I know I can just edit the .git/config file, but it seems there should be an easier way.
Pat Notz
  • 208,672
  • 30
  • 90
  • 92
7 answers

How do I clone a specific Git branch?

Git clone will clone remote branch into local. Is there any way to clone a specific branch by myself without switching branches on the remote repository?
  • 41,923
  • 8
  • 26
  • 18
50 answers

How do I get the current branch name in Git?

How do I get the name of the current branch in Git?
  • 45,873
  • 18
  • 40
  • 57
13 answers

Move existing, uncommitted work to a new branch in Git

I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one? I want to reset my current branch while…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
25 answers

How do I create a remote Git branch?

I created a local branch. How do I push it to the remote server? UPDATE: I have written a simpler answer for Git 2.0 here.
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
31 answers

`git fetch` a remote branch

The remote repository contains various branches such as origin/daves_branch: $ git branch -r origin/HEAD -> origin/master origin/daves_branch origin/master How do I switch to daves_branch in the local repository so that it tracks…
  • 34,836
  • 11
  • 47
  • 77
16 answers

How do I safely merge a Git branch into master?

A new branch from master is created, we call it test. There are several developers who either commit to master or create other branches and later merge into master. Let's say work on test is taking several days and you want to continuously keep test…
  • 28,814
  • 4
  • 19
  • 16
22 answers

Branch from a previous commit using Git

If I have N commits, how do I branch from the N-3 commit?
dole doug
  • 34,070
  • 20
  • 68
  • 87
21 answers

Showing which files have changed between two revisions

I want to merge two branches that have been separated for a while and wanted to know which files have been modified. Came across this link: (moved to which was quite useful. The tools to compare…
  • 29,188
  • 15
  • 39
  • 42
2 3
99 100