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
1098
votes
12 answers

Git: How do I list only local branches?

git branch -a shows both remote and local branches. git branch -r shows remote branches. Is there a way to list just the local branches?
munyengm
  • 15,029
  • 4
  • 24
  • 34
1036
votes
14 answers

Update Git branches from master

I have four branches (master, b1, b2, and b3). After I worked on b1-b3, I realized I have something to change on branch master that should be in all other branches. I changed what I needed in master and... here is my problem: How do I update all…
Ionuț Staicu
  • 21,360
  • 11
  • 51
  • 58
1020
votes
11 answers

Move branch pointer to different commit without checkout

To move the branch pointer of a checked out branch, one can use the git reset --hard command. But how to move the branch pointer of a not-checked out branch to point at a different commit (keeping all other stuff like tracked remote branch)?
Mot
  • 28,248
  • 23
  • 84
  • 121
924
votes
10 answers

Cleaning up old remote git branches

I work from two different computers (A and B) and store a common git remote in the dropbox directory. Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel. Now while on computer…
Jayesh
  • 51,787
  • 22
  • 76
  • 99
884
votes
17 answers

Rename master branch for both local and remote Git repositories

I have the branch master which tracks the remote branch origin/master. I want to rename them to master-old both locally and on the remote. Is this possible? For other users who tracked origin/master (and who always updated their local master branch…
Albert
  • 65,406
  • 61
  • 242
  • 386
875
votes
22 answers

How do I list all remote branches in Git 1.7+?

I've tried git branch -r, but that only lists remote branches that I've tracked locally. How do I find the list of those that I haven't? (It doesn't matter to me whether the command lists all remote branches or only those that are untracked.)
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
850
votes
5 answers

View a file in a different Git branch without changing branches

Is it possible to open a file in a git branch without checking out that branch? How? Essentially I want to be able to open a file in my github pages branch without switching branches all the time. I don't want to modify it, just want to view it.
Schneems
  • 14,918
  • 9
  • 57
  • 84
783
votes
9 answers

How to create a new branch from a tag?

I'd like to create a new master branch from an existing tag. Say I have a tag v1.0. How to create a new branch from this tag?
Andrew
  • 227,796
  • 193
  • 515
  • 708
780
votes
6 answers

Git remote branch deleted, but still it appears in 'branch -a'

Let's say I had a branch named coolbranch in my repository. Now, I decided to delete it (both remotely and locally) with: git push origin :coolbranch git branch -D coolbranch Great! Now the branch is really deleted. But when I run git branch -a I…
yonix
  • 11,665
  • 7
  • 34
  • 52
756
votes
10 answers

Git branch command behaves like 'less'

When I use the git branch command to list all branches, I see the output of git branch | less. The command git branch is supposed to show a list of branches, like ls does for files. This is the output I get: How do I get the default behaviour of…
DenicioCode
  • 8,668
  • 4
  • 18
  • 33
719
votes
14 answers

How is a tag different from a branch in Git? Which should I use, here?

I am having some difficulty understanding how to use tags versus branches in git. I just moved the current version of our code from cvs to git, and now I'm going to be working on a subset of that code for a particular feature. A few other developers…
Bialecki
  • 30,061
  • 36
  • 87
  • 109
669
votes
2 answers

Why does git perform fast-forward merges by default?

Coming from mercurial, I use branches to organize features. Naturally, I want to see this work-flow in my history as well. I started my new project using git and finished my first feature. When merging the feature, I realized git uses fast-forward,…
Florian Pilz
  • 8,002
  • 4
  • 22
  • 30
623
votes
11 answers

Push commits to another branch

Is it possible to commit and push changes from one branch to another. Assume I commited changes in BRANCH1 and want to push them to BRANCH2. From BRANCH1, is it valid to do: git push origin **BRANCH2** And then reset BRANCH1?
jviotti
  • 17,881
  • 26
  • 89
  • 148
597
votes
10 answers

Using Git, show all commits that are in one branch, but not the other(s)

I have an old branch, which I would like to delete. However, before doing so, I want to check that all commits made to this branch were at some point merged into some other branch. Thus, I'd like to see all commits made to my current branch which…
sircolinton
  • 6,536
  • 3
  • 21
  • 19
567
votes
10 answers

How do I run git log to see changes only for a specific branch?

I have a local branch tracking the remote/master branch. After running git-pull and git-log, the log will show all commits in the remote tracking branch as well as the current branch. However, because there were so many changes made to the remote…
Highway of Life
  • 22,803
  • 16
  • 52
  • 80