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
1
vote
1 answer

One git command to create new local branch, push to origin, track origin

A common part of my workflow is: git checkout -b new_branch origin/master git push origin new_branch git branch --set-upstream-to origin/new_branch Is there a way this could be boiled down to one command? I'd like to be able to set up an alias so…
Brian Risk
  • 1,006
  • 9
  • 17
1
vote
4 answers

Upon $ Git checkout branchName, all changes (committed or not/ staged or not) appear on branch switched

Git / branch weird behavior Recently, I had to recover my computer and reinstalled ALL software again. Git is behaving in a manner I am not familiar with. I did $ git init $ git branch -b newBranch $ git checkout newBranch After this I did some…
wowiamhere
  • 61
  • 1
  • 6
1
vote
1 answer

Untangling GIT mess - branch/merge some commits after the fact

A classic case of "don't start from here"... as is the way of all things, disorganisation has descended on our Git, tree looks something like this: A-B-C-D master \ E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T... exciting new stuff Whereas the…
John U
  • 2,617
  • 2
  • 22
  • 35
1
vote
3 answers

How do I recover from a lost git branch

I have a project I am working on which I started on a local repo. I recently had someone create a github repo and I uploaded the local repo to github (there were various errors and suggestions, but it eventually looked like it was up there.) After…
David Rogers
  • 3,210
  • 3
  • 24
  • 27
1
vote
3 answers

Is there any way to branch only specific files git? (aka Orphan branch)

I have a project in git, and I want to branch a few select files (so the main git repo should have all the files in a certain directory, but the branch should only have a select 10).
Charles Shiller
  • 873
  • 2
  • 9
  • 31
1
vote
2 answers

Switching branch does not update android studio

I have a stable branch that I am doing some work on. Then to do some experimental stuff, I create another branch called experi and then started doing some work there. Then I switch back to my stable branch. However, android studio is still showing…
Nouvel Travay
  • 5,562
  • 11
  • 34
  • 60
1
vote
3 answers

Move branch commits to current one as uncommitted changes to working directory?

Lets say that I work on branchA, and need to temporary commit all the uncommitted changes. So I create branchB, and commit everything. After some time, I need to move all those changes back to branchA as uncommitted changes. (Some changes where to…
przemo_li
  • 3,703
  • 3
  • 31
  • 52
1
vote
1 answer

Should Patches have own branch in git workflow?

I am reading here about git branching strategie. Where to assign patches? should patches have their own branch? If yes where should patches branched from? from master branch?
Ronald
  • 2,759
  • 4
  • 25
  • 37
1
vote
2 answers

Checkout second Git branch without losing local changes

I have checked out a particular branch from my master. I created new classes propery files etc. in my local Eclipse and did the testing. I have not added/committed those classes/files to my local git repo. So after this successful prototype testing…
user721025
  • 173
  • 3
  • 13
1
vote
2 answers

How to view all tags in a git repository (more than 29)?

I am going through a texbook on Flask (Python framework). Examples are provided in git repository: https://github.com/miguelgrinberg/flasky Each example is a branch tag, but git show-branch -a does not show all of them, because as I understand the…
YKY
  • 2,025
  • 5
  • 18
  • 25
1
vote
1 answer

What branch orphan commits belong to? (Git, Github)

I have some orphan commits inside my Github repo. They are not present inside of any branch or my local repo, and I can only see them if I select a specific issue with the list of related commits. Is there any way I can merge these commits into…
Felipe Peña
  • 2,324
  • 4
  • 18
  • 35
1
vote
2 answers

Push master without feature branches

I've done quite a lot of search on this problem but didn't find an answer, though it seems to be a common scenario. Sorry if it is still a duplicate. I use Git to manage my Java source files. I'm the only developer. I created a 'remote' repository…
1
vote
3 answers

Git best practice with new database

Question regarding Git best practices. When making a major new version of a project (in my case it's a Codeigniter project) I am faced with two options: Create a new branch (e.g. branch version2) Create a copy of existing project folder and make it…
GluePear
  • 5,766
  • 10
  • 51
  • 95
1
vote
2 answers

Discard Git commits & merge feature branch back to Master

First I worked and made 3 commits on Master branch: Wijzing 1, 2, 3. Then I did checkout... on commit Wijziging 1. Then I created a new branch new-feature and started making changes. Now I want to throw away the 2 commits: Wijzing 2 and Wijziging…
Jim Clermonts
  • 1,270
  • 6
  • 23
  • 64
1
vote
1 answer

How to test a version of an app from a dedicated branch on a remote server?

Locally I have checked out a new branch, changed code of my app, committed these changes into that new dedicated branch. Now I would like to test this version of my app on a server. How may I do it? Usually my workflow is as follows. Locally I have…
Green
  • 21,978
  • 45
  • 138
  • 223
1 2 3
99
100