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

How to recover HEAD problems in filtered repository?

After having split the repository in my workspace into two by filtering, I cloned them "bare" into new origins, and then continued to work in a cloned workspace on the current branch without a problem. Several commits later I merged my branch into…
U. Windl
  • 3,480
  • 26
  • 54
1
vote
1 answer

Do I need to Clone repository for adding a custom branch

I have downloaded a Zip folder of Master branch from a gogs repository and after initializing git in that folder, I have added my own branch and made my own changes. Now my question is, do I have to CLONE the project in order for adding a new branch…
user16333885
1
vote
2 answers

How to merge current local branch with specific single commit from different branch in remote repository?

Lets say I have this in my local: master branch-a branch-b and I have this in my remote repository: master branch-a branch-b branch-c Conditions: I own the remote repository. I have all needed accesses. My local branch-b and remote branch-b…
Faris Han
  • 525
  • 3
  • 16
1
vote
2 answers

Gitlab repository with multiple branches to local

This is more of a clarification question. In Gitlab, you can create multiple branches from the same repository, so the repository myrepository.git can have a master branch and then a development branch for example. When I clone the repository to a…
Gavin Siu
  • 81
  • 1
  • 9
1
vote
1 answer

How to make git bash show branch name in submodules

Git bash shows the branch name as (master) But when using submodules, it now shows the hash and not the name, for example: ((445c03f...)) How can I make it show the name of the branch while inside a submodule?
JuanKB1024
  • 324
  • 1
  • 17
1
vote
1 answer

safe way to revert git branch to last commit?

I have checked out to one of the branches local, I committed the changes made and I did git pull origin master there was a conflict in one of my files named app.scss , I started solving the conflicts in this file by mistake I deleted my changes I…
The Dead Man
  • 6,258
  • 28
  • 111
  • 193
1
vote
1 answer

How to manage Multiple branches on Git

I am working on a project using git where I've been assigned two tasks. Let's assume task A and task B. I started by forking the project and created a branch named A at this point I was not aware I had to do task B. After forking the project I've…
Lopez
  • 461
  • 5
  • 19
1
vote
2 answers

Not able to checkout from a locally created git branch

I created a new branch using : git checkout -b DikshaPython Now I am not able to checkout from the branch and move back to master. Even when I close the window of gitBash and open it again it shows that I am still on this branch. I have used…
Diksha Nasa
  • 135
  • 3
  • 13
1
vote
2 answers

How do I uncommit last merge on a protected branch?

How do I uncommit last merge on a protected branch? git reset --hard HEAD~1 git push -f origin master I did the following after noticing that the last merge had a UI bug on production, but not local environment. $ git push -f origin master Total 0…
Sayaman
  • 1,145
  • 4
  • 14
  • 35
1
vote
1 answer

Git: what is the difference between dev and refs/heads/dev?

From recent work in devops, it seems as though there are "two ways" to check out a branch in git: using the plain branch name, e.g. dev, or using the branch name prefixed with refs/heads/, e.g. refs/heads/dev. What is the difference between the…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
1
vote
1 answer

Sourcetree existing repo has no brances and cannot create one

I have an existing repo which I connected to my gitlab via ssh I am just trying to create my branch in sourcetree so that i push my changes there but in getting an error "not a valid object name master" is there any part that i skipped because my…
Button Press
  • 623
  • 6
  • 26
1
vote
1 answer

Understanding Branch Changes

There really is a question at the end of this wall of text. It just takes some set-up to get to. I appreciate your bearing with me. I have a project I'm tech lead on, with two other developers. Some time earlyish but not actually at the beginning of…
Dan Ray
  • 21,623
  • 6
  • 63
  • 87
1
vote
2 answers

Will git tag automatically move to main branch when merged?

I have created a git tag in the dev branch. But if I merge it from dev to main branch, will the git tag be automatically be added in the main as well?
Muzzlet
  • 219
  • 3
  • 18
1
vote
1 answer

How to undo a discard changes in VSCode

I'm new to git, I was building a project with couple of branches. I was in branch B with uncomitted changes and then I run this command: git checkout -b C to move to new branch, let's call it branch C. In branch C I uncommit those changes and since…
Arik Jordan Graham
  • 301
  • 1
  • 3
  • 9
1
vote
4 answers

Starting branch2 off of branch1 vs starting branch2 off of master and merge in branch1

I have a feature branch (branch1) that was approved but not yet merged into to master (have to wait for deployment CI to be fixed). I want to get started on another branch (branch2) which needs branch1's changes in it. Would it make more sense to…
user15909643