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
565
votes
7 answers

How do I push a local Git branch to master branch in the remote?

I have a branch called develop in my local repo, and I want to make sure that when I push it to origin it's merged with the origin/master. Currently, when I push it's added to a remote develop branch. How can I do this?
picardo
  • 24,530
  • 33
  • 104
  • 151
553
votes
4 answers

What is the difference between origin and upstream on GitHub?

What is the difference between origin and upstream on GitHub? When a git branch -a command is executed, some branches it displays have a prefix of origin (remotes/origin/..) while others have a prefix of upstream (remotes/upstream/..).
jan
  • 5,901
  • 4
  • 16
  • 5
553
votes
12 answers

Git undo local branch delete

I just deleted the wrong branch with some experimental changes I need with git branch -D branchName. How do I recover the branch?
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
498
votes
12 answers

How do I merge changes to a single file, rather than merging commits?

I have two branches (A and B) and I want to merge a single file from branch A with a corresponding single file from Branch B.
Isuru
  • 7,893
  • 8
  • 30
  • 38
477
votes
12 answers

Show just the current branch in Git

Is there a Git command equivalent to: git branch | awk '/\*/ { print $2; }'
Ollie Saunders
  • 7,787
  • 3
  • 29
  • 37
474
votes
16 answers

How to determine when a Git branch was created?

Is there a way to determine when a Git branch was created? I have a branch in my repo and and I don't remember creating it and thought maybe seeing the creation timestamp would jog my memory.
oz10
  • 153,307
  • 27
  • 93
  • 128
430
votes
10 answers

Creating a new empty branch for a new project

We are using a git repository to store our project. We have our branches departing from the original branch. But now we want to create a small new project to track some documentation. For that we would want to create a new empty branch to start…
fazineroso
  • 7,196
  • 7
  • 31
  • 42
400
votes
14 answers

Git "error: The branch 'x' is not fully merged"

Here are the commands I used from the master branch git branch experiment git checkout experiment Then I made some changes to my files, committed the changes, and pushed the new branch to GitHub. git commit . -m 'changed files' git push -u origin…
mellowsoon
  • 22,273
  • 19
  • 57
  • 75
392
votes
8 answers

How to keep a branch synchronized/updated with master?

At the moment git is doing my head in, I cannot come up with the best solution for the following. There are two branches, one called master and one called mobiledevicesupport. I want to keep mobiledevicesupport as a continuous branch that will be…
Mr. EZEKIEL
  • 4,084
  • 3
  • 14
  • 9
390
votes
7 answers

How to pull remote branch from somebody else's repo

I've got a project hosted on GitHub which somebody has forked. On their fork, they've created a new branch "foo" and made some changes. How do I pull their "foo" into a new branch also named "foo" in my repo? I understand they could submit a pull…
Colin O'Dell
  • 8,386
  • 8
  • 38
  • 75
386
votes
8 answers

How do I commit only some files?

I have two projects. One is the "official" project and the second is a light modification (some files added). I created new branch and I put new files to them. But in during development some files common to both branches is changed. How do I commit…
Nips
  • 13,162
  • 23
  • 65
  • 103
373
votes
12 answers

fetch in git doesn't get all branches

I have cloned a repository, after which somebody else has created a new branch, which I'd like to start working on. I read the manual, and it seems dead straight easy. Strangely it's not working, and all the posts I've found suggest I'm doing the…
Edward Newell
  • 17,203
  • 7
  • 34
  • 36
363
votes
4 answers

How do I make a branch point at a specific commit?

In Git, I understand that a branch is a pointer to a commit. How do I make a specific branch point to a specific commit? Say I want to make master point at 1258f0d0aae..., how do I do that?
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
345
votes
1 answer

Complex Git branch name broke all Git commands

I was trying to create a branch from master with the following command, git branch SSLOC-201_Implement___str__()_of_ProductSearchQuery when Git suddenly stopped responding. I suspect the unescaped () are to blame, somehow. Now, whenever I try to…
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
342
votes
8 answers

Git merge errors

I have a git branch called 9-sign-in-out with perfectly working code, and I want to turn it into the master. I'm currently on the master branch. $ git branch 9-sign-in-out * master I'm trying to switch to 9-sign-in-out branch, but it doesn't allow…
Sayanee
  • 4,957
  • 4
  • 29
  • 35