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.

3129 questions
42 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
  • 439,004
  • 38
  • 121
  • 160
38 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?
  • 116,401
  • 20
  • 72
  • 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?
  • 331,320
  • 107
  • 203
  • 204
21 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
  • 79,163
  • 10
  • 43
  • 46
17 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
  • 54,946
  • 5
  • 18
  • 16
46 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
  • 53,429
  • 11
  • 54
  • 71
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
  • 201,110
  • 30
  • 89
  • 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?
  • 39,743
  • 7
  • 24
  • 18
12 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
  • 72,722
  • 37
  • 117
  • 167
24 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
  • 101,109
  • 43
  • 115
  • 152
48 answers

How do I get the current branch name in Git?

How do I get the name of the current branch in Git?
  • 42,513
  • 18
  • 39
  • 55
32 answers

Git fetch remote branch

The remote contains various branches such as origin/daves_branch: $ git branch -r origin/HEAD -> origin/master origin/daves_branch origin/master How do I checkout daves_branch locally so that it tracks origin/daves_branch? I tried: $ git fetch…
  • 32,703
  • 11
  • 44
  • 72
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,096
  • 3
  • 18
  • 16
21 answers

Branch from a previous commit using Git

If I have N commits, how do I branch from the N-3 commit?
dole doug
  • 32,220
  • 20
  • 64
  • 86
18 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: which was quite useful. The tools to compare branches I've come across…
  • 28,628
  • 14
  • 38
  • 41
2 3
99 100