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

Copying content of a directory on another branch

I have 2 branches on github: master gh-pages My branch master has the directory _site which contains all the files that I need to be stored on the root of gh-pages. I am using the git command: git checkout master -- _site To copy the contents of…
1
vote
4 answers

Commits on main branch being added to other branches

Let's say there are 4 files A, B, C, and D, of which the files A, B, C are committed on the main branch. I now create a new branch (let's call it sub-branch), do git checkout sub-branch and make changes, and commit file D only. But, when I push the…
Prajwal Kulkarni
  • 1,480
  • 13
  • 22
1
vote
2 answers

How to implement a custom Rubocop rule for checking git branch naming convention?

For example, I need to check the correctness of git branch naming - it should contain ticket ID similarly to this: module Rails class GitBranchName < RuboCop::Cop::Cop MSG = "Use correct branch name by pattern '{TicketID}-{Description}'.…
1
vote
1 answer

Git branching on a MVC project - 2 or more views with shared core

I'm starting to learn git branching, and I'm developing with other people a web based MVC project (using Zend). We just worked on the master branch since today; now we need to develop tow different views (html aspect, css & co.), so we created a…
Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
1
vote
2 answers

Git: If I've been working in detached head state for multiple commits, will I lose anything by getting out of it?

A while ago I checked out a previous commit, then checked out my most recent commit again. I didn't realize this at the time, but that left me in a detached head state. I've done multiple commits since then, and am still in the detached head state.…
gkeenley
  • 6,088
  • 8
  • 54
  • 129
1
vote
1 answer

Different branches in repositories

When I see my branches in a local repository with git branch in the terminal it prints only one, which is master But when I go to the gitlab page I have two branches that are main and master, the main branch by default is main but in master I have…
Márquez
  • 91
  • 7
1
vote
1 answer

Git merge branch delete all my change file

Me and my co-worker usually merge each other branchs before we create merge request .But lastime when he merge my branch i found out there some errors so he do revert his code. The problem right now is that when i merge his branch, all my changes…
Lê VỸ
  • 11
  • 1
1
vote
2 answers

Git branch and ls

I'm not sure if this is the right place to ask this, please redirect me if not. I'm new to git and while learning it I stumbled upon this. How does git branch branchName and 'ls' work with each other. For eg: If I have a master and test branch and…
Diff.Thinkr
  • 855
  • 1
  • 8
  • 16
1
vote
0 answers

Git rebase flagging ALL changes?

We're trying to maintain a set of configuration files in a git repo. From time to time, we make a release of the latest configuration to a target system. We then make further changes to the repo While we do this the users of that system may update…
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
1
vote
0 answers

GITHUB how to set a rule, that will allow push only from master branch (to deploy branch)

Sorry for asking question, thas is maybe answered somewhere else. My problem is that i have branch for deployment and i want to set a rule, that will allow only push from master (where we have always working code) -> so nobody would push from their…
MatUrb
  • 11
  • 1
1
vote
2 answers

how to list all 'active' branches in git containing unmerged commits

I'm struggling to make sense of the history of a couple of very large repositories that have hundreds of (old) branches which never have been deleted (even though work on most of these branches is 'done'). I'm trying to find a way to generate a list…
mwallner
  • 985
  • 11
  • 23
1
vote
2 answers

Prevent git from creating branches that use names of remotes?

I often accidentally checkout remote tracking branches incorrectly: git checkout -b origin/fixbugs The -b should be a -t. This mistake creates a branch called "origin/fixbugs". How could I get git to give me an error instead of creating this branch…
idbrii
  • 10,975
  • 5
  • 66
  • 107
1
vote
1 answer

I merged a branch, and not all commits had been pushed. How to add the remaining commits?

I had a branch. Say there were commits A -- B -- C -- D I pushed it. Then I added more: A -- B -- C -- D -- E -- F I merged. How do I add E and F?
Mykola Tetiuk
  • 153
  • 1
  • 13
1
vote
1 answer

Github hook : Is it possible to listen to branch specific push?

I am setting up auto-deployment for a git repo. I am using the github hooks to listen to the "push" event. But, this event is getting triggered for every branch. Now, my repo has 20 branches and I am concerned only with the push to "xyz" branch. Is…
Keval Bhogayata
  • 4,422
  • 3
  • 13
  • 36
1
vote
1 answer

Merge a commit from a branch in repositoryA to a branch in repositoryB

Assuming I have two repositories called repositoryA and repositoryB. I need to merge a commit abcdefgh which is in a branch in repositoryA and called branchA to another branch called branchB and located in repositoryB. in repositoryB: git checkout…