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.

2836 questions
17987
votes
39 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
  • 400,554
  • 38
  • 116
  • 156
9328
votes
34 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 branch? In case you need to rename remote branch as…
Forrest
  • 101,971
  • 19
  • 69
  • 107
7266
votes
40 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?
readonly
  • 306,152
  • 101
  • 198
  • 201
5491
votes
15 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
  • 72,599
  • 10
  • 41
  • 46
4757
votes
15 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
  • 49,329
  • 5
  • 17
  • 14
4370
votes
42 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
  • 50,723
  • 11
  • 51
  • 70
3679
votes
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
  • 186,044
  • 29
  • 86
  • 92
3389
votes
7 answers

How do I clone a specific Git branch?

Git clone will behave copying remote current working branch into local. Is there any way to clone a specific branch by myself without switching branches on the remote repository?
Scud
  • 36,193
  • 6
  • 23
  • 18
3387
votes
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
  • 67,996
  • 36
  • 114
  • 164
3347
votes
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
  • 91,561
  • 40
  • 112
  • 147
3033
votes
38 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…
mike628
  • 36,755
  • 16
  • 37
  • 51
2550
votes
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…
David
  • 28,483
  • 10
  • 38
  • 68
2325
votes
14 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…
moe
  • 25,936
  • 3
  • 17
  • 16
2207
votes
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: http://linux.yyz.us/git-howto.html which was quite useful. The tools to compare branches I've come across…
johannix
  • 27,528
  • 14
  • 37
  • 41
2047
votes
18 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
  • 28,350
  • 20
  • 62
  • 84
1
2 3
99 100