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.

3014 questions
41 answers

How do I delete a Git branch locally and remotely?

I want to delete a branch both 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…
Matthew Rankin
  • 424,668
  • 38
  • 118
  • 160
36 answers

How do I rename a local Git branch?

I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories. How can I rename a local branch which hasn't been pushed to a remote repository? In case you need to rename a remote branch as…
  • 111,363
  • 20
  • 71
  • 107
41 answers

How to remove local (untracked) files from the current Git working tree

How do you delete untracked local files from your current working tree?
  • 321,454
  • 105
  • 202
  • 204
20 answers

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

I'd like to move the last several commits I've committed to master to a new branch and take master back to before those commits were made. Unfortunately, my Git-fu is not strong enough yet, any help? I.e. How can I go from this master A - B - C - D…
Mark A. Nicolosi
  • 76,625
  • 10
  • 43
  • 46
16 answers

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

I want to be able to do the following: Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b) Push the local branch to the remote repository (publish), but make it trackable so git pull and git push…
Roni Yaniv
  • 52,666
  • 5
  • 18
  • 16
45 answers

How to clone all remote branches in Git

I have a master and a development branch, both pushed to GitHub. I've cloned, pulled, and fetched, but I remain unable to get anything other than the master branch back. I'm sure I'm missing something obvious, but I have read the manual and I'm…
Peter Coulton
  • 52,401
  • 11
  • 52
  • 71
22 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
  • 195,198
  • 30
  • 88
  • 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?
  • 38,343
  • 7
  • 24
  • 18
9 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
  • 70,774
  • 37
  • 116
  • 166
24 answers

How do you create a remote Git branch?

I created a local branch which I want to 'push' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch. However, my workflow is slightly different. First I want to create a local branch, and I…
Jesper Rønn-Jensen
  • 97,441
  • 42
  • 114
  • 150
45 answers

How to get the current branch name in Git?

I'm from a Subversion background and, when I had a branch, I knew what I was working on with "These working files point to this branch". But with Git I'm not sure when I am editing a file in NetBeans or Notepad++, whether it's tied to the master or…
  • 40,385
  • 17
  • 38
  • 53
31 answers

Git fetch remote branch

My colleague and I are working on the same repository. We've branched it into two branches, each technically for different projects, but they have similarities, so we'll sometimes want to commit back to the *master from the branch. However, I have…
  • 30,824
  • 10
  • 42
  • 70
15 answers

What is the best (and safest) way to 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…
  • 27,306
  • 3
  • 17
  • 16
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,168
  • 14
  • 37
  • 41
19 answers

Branch from a previous commit using Git

If I have n commits, how can I branch from the n-3 commit? I can see the hash of every commit.
dole doug
  • 30,550
  • 20
  • 63
  • 84
2 3
99 100