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
2 answers

Is it common to dedicate a git branch for a separate project?

In the team I just joined, they have a git repository structured in this way: -----------------> Main project |-----------> Sub-project1 |-----------> Sub-project2 So, development is done in the "Main project" main trunk (and short term…
Pietro
  • 12,086
  • 26
  • 100
  • 193
1
vote
2 answers

Cannot remove 40 characters named branches from Gitlab

I have a Gitlab repository with stale branches that I have not noticed before. I think they was created by Gitlab when one of the users made a change to the repository with the build in file editor. They have auto generated names looking like this …
Ivan Stasiuk
  • 292
  • 6
  • 12
1
vote
2 answers

Accidentally commited to main branch instead of develop branch. Now my main branch is ahead of the develop branch. How can I fix it?

I have a develop branch and a main branch. Of course, I was supposed to be developing on the develop branch (but I was on main). I work alone in this project, so the only changes were made by me. This is what I did: Both main and the develop were on…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
1
vote
2 answers

git: How to get more information (when, sha) about a branch merging into another?

I found git branch -r --merged master to see all the branches ever merged into master Our flow is pretty standard: develop == feature branch --> develop == release branch --> master ("==" create a branch from; "-->" PR into) I want to find out when…
Richard Haven
  • 63
  • 1
  • 4
1
vote
1 answer

What does it mean to close a branch?

And what are the advantages of closing a branch? And what happens if I don't do that. I work in a team and we use Git in Bitbucket. Some colleagues always say that it is very important to close the branch. But why?
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
1
vote
1 answer

List all branches from develop

I need to find all the branches taken from develop, as apposed to master. From a programming point of view, I could: List all branches For each branch, use merge-base to get the first ancestor of develop branch and master branch Compare the…
1
vote
1 answer

How to move files from one git branch to another

I have a git repository with 2 branches. I want to move all the files of the 2nd branch to the main branch. Is it possible to do so? If yes, how?
FC5570
  • 163
  • 4
  • 12
1
vote
1 answer

Modify previous commit without modifying working directory

D / A-B-C-E Branch D is my current working directory, however, I want to 'clone' C again, make some changes and commit them to create E without having to change anything I did in D. Then I can continue to develop on D. How can I…
CoolGravatar
  • 5,408
  • 7
  • 35
  • 42
1
vote
3 answers

Move commits into new branch with merge commits

I have a linear history like so ----a--b--c--d--e--f---- main I want to move a series of commits into a new branch and create a merge commit into the old branch, creating a non-linear history like so ----a-------x--d'--e'--f'-- main \ …
mdcq
  • 1,593
  • 13
  • 30
1
vote
2 answers

How do I divide a single, large git branch into two successive branches?

I have some branches in git that look like: master b1 ↓ ↓ A -- B -- C -- D -- E But D ... E turned out to be an unexpectedly nontrivial change, so I would like to see this instead: master b3 ↓ ↓ A -- B -- C…
trbabb
  • 1,894
  • 18
  • 35
1
vote
3 answers

How to deal with main and master in Github

I have opened a Git repository with readme file in Github, and then use below to push local code to this repository git push origin master It shows two branchs: main and master, but with git branch, it only shows main branch $ git branch *…
Annie
  • 85
  • 3
  • 14
1
vote
1 answer

Working with git stash with different branches

I have two branches feature/A and feature/B. I have modified the files of feature/A and apply git stash command to save my work and git checkout feature/B to switch to other branch. Now on feature/B I have modified files and applies git stash to…
Harry
  • 154
  • 4
  • 15
1
vote
1 answer

Unable to push remote repository to my repo

I cloned and pulled a repository on a branch develop from github to my local repository and when i tried to 'git push origin develop' it to my repository, it brought the error below: remote: Permission to adex001/Fast-Food-Fast.git denied to…
Dlaw
  • 21
  • 3
1
vote
1 answer

Determine parent branch/commit from git history

I've got following history in git: * 02e085a (master) readme update | * 1d940da (HEAD -> b1) search.py | | * 7aaa12d (b2) file2 | |/ | * 7be9db9 file1 |/ * 22601c0 initial commit Now I'm on b2 and I would like to get the point, where b2 branched…
ST Renegade
  • 311
  • 3
  • 14
1
vote
0 answers

Getting a 'failed to push some refs to github' error when I try to push new changes to github

Hello I am getting an error everytime I try to push my changes to github. I have tried reading other similar questions on stack overflow but none of the solutions are working for me ~/SkillSwap/skill_swap_client // ♥ > git add…