Questions tagged [branch]

A "branch" is a term used in version control systems to represent an independent line of development. Depending on the system, a repository can contain one or more branches. Branches are merged when changes need to propagate from one branch into another.

Filter by
Sorted by
Tagged with
51 votes
2 answers
9k views

What exactly do we mean by "branch"?

Long story short... As far as I can tell, the term "branch" (in Git parlance) may refer to related but different things: a non-symbolic reference/pointer to a commit, the name of such a reference (e....
jub0bs's user avatar
  • 60.5k
3988 votes
23 answers
1.7m views

Make an existing Git branch track a remote branch?

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch? I know I can just edit the .git/config file, but it seems there should be an ...
Pat Notz's user avatar
  • 208k
7997 votes
41 answers
3.1m views

How do I remove local (untracked) files from the current Git working tree?

How do I delete untracked local files from the current working tree?
readonly's user avatar
  • 343k
588 votes
28 answers
699k views

How to find the nearest parent of a Git branch

Let's say I have the following local repository with a commit tree like this: master --> a \ \ develop c --> d \ \ feature ...
Peter Farmer's user avatar
  • 8,990
1005 votes
27 answers
949k views

How do I clone a single branch in Git?

I have a local Git repository in ~/local_repo. It has a few branches: $ git branch * master rails c c++ To clone the local repository, I do: $ git clone ~/local_repo new_repo Initialized empty ...
Casey Rodarmor's user avatar
1517 votes
24 answers
636k views

Can I recover a branch after its deletion in Git?

If I run git branch -d XYZ, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command?
prosseek's user avatar
  • 182k
1519 votes
12 answers
737k views

Default behavior of "git push" without a branch specified

I use the following command to push to my remote branch: git push origin sandbox If I say git push origin does that push changes in my other branches too, or does it only update my current branch? ...
Debajit's user avatar
  • 46.3k
3878 votes
50 answers
3.0m views

How do I get the current branch name in Git?

How do I get the name of the current branch in Git?
mike628's user avatar
  • 45.8k
113 votes
12 answers
39k views

When should you branch?

When working with a SCM system, when should you branch?
Ben Aston's user avatar
  • 53.6k
2249 votes
34 answers
2.5m views

How do I fetch all Git branches?

I cloned a Git repository containing many branches. However, git branch only shows one: $ git branch * master How would I pull all the branches locally so when I do git branch, it shows the following?...
David542's user avatar
  • 106k
394 votes
10 answers
116k views

In git, is there a simple way of introducing an unrelated branch to a repository?

While helping a friend with a git problem today, I had to introduce a branch that needed to be totally separate from the master branch. The contents of this branch really had a different origin from ...
hillu's user avatar
  • 9,413
212 votes
16 answers
96k views

Track all remote git branches as local branches

Tracking a single remote branch as a local branch is straightforward enough. $ git checkout --track -b ${branch_name} origin/${branch_name} Pushing all local branches up to the remote, creating new ...
Janson's user avatar
  • 2,381
580 votes
27 answers
258k views

Finding a branch point with Git?

I have a repository with branches master and A and lots of merge activity between the two. How can I find the commit in my repository when branch A was created based on master? My repository ...
Jochen's user avatar
  • 7,260
293 votes
8 answers
175k views

Using the slash character in Git branch name

I'm pretty sure I saw somewhere in a popular Git project the branches had a pattern like "feature/xyz". However when I try to create a branch with the slash character, I get an error: $ git branch ...
user avatar
2581 votes
51 answers
895k views

How do I delete all Git branches which have been merged?

How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?
Nyambaa's user avatar
  • 38.9k
3675 votes
25 answers
2.8m views

How do I create a remote Git branch?

I created a local branch. How do I push it to the remote server? UPDATE: I have written a simpler answer for Git 2.0 here.
Jesper Rønn-Jensen's user avatar
1210 votes
16 answers
459k views

What do "branch", "tag" and "trunk" mean in Subversion repositories?

I've seen these words a lot around Subversion (and I guess general repository) discussions. I have been using SVN for my projects for the last few years, but I've never grasped the complete concept of ...
grapefrukt's user avatar
69 votes
5 answers
18k views

Trimming Git Commits/Squashing Git History

I check my code into a Git branch every few minutes or so, and the comments end up being things like "Everything broken starting again" and other absurdities. Then every few minutes/hours/days I do a ...
Dan Rosenstark's user avatar
2516 votes
22 answers
1.2m views

Branch from a previous commit using Git

If I have N commits, how do I branch from the N-3 commit?
dole doug's user avatar
  • 34k
248 votes
6 answers
187k views

What is a tracking branch?

Can someone explain a "tracking branch" as it applies to git? Here's the definition from git-scm.com: A 'tracking branch' in Git is a local branch that is connected to a remote branch. When ...
jerhinesmith's user avatar
  • 15.2k
518 votes
5 answers
177k views

What are the differences between git branch, fork, fetch, merge, rebase and clone?

I want to understand the difference between a branch, a fork and a clone in Git? Similarly, what does it mean when I do a git fetch as opposed to a git pull? Also, what does rebase mean in ...
jackiekazil's user avatar
  • 5,696
202 votes
11 answers
103k views

Listing and deleting Git commits that are under no branch (dangling?)

I've got a Git repository with plenty of commits that are under no particular branch, I can git show them, but when I try to list branches that contain them, it reports back nothing. I thought this ...
Samer Buna's user avatar
  • 8,821
85 votes
3 answers
39k views

Git - how to force merge conflict and manual merge on selected file

We maintain web application which has common master branch and many parallel branches, one for each installation, each have few specific changes. Source code is managed in git and it is terrific tool ...
Stepan's user avatar
  • 1,430
1206 votes
25 answers
939k views

Find out which remote branch a local branch is tracking

See also: How can I see which Git branches are tracking which remote / upstream branch? How can I find out which remote branch a local branch is tracking? Do I need to parse git config output, or ...
readonly's user avatar
  • 343k
369 votes
8 answers
771k views

Why do I have to "git push --set-upstream origin <branch>"?

I created a local branch for testing Solaris and Sun Studio. I then pushed the branch upstream. After committing a change and attempting to push the changes: $ git commit blake2.cpp -m "Add ...
jww's user avatar
  • 97.5k
1299 votes
20 answers
1.3m views

master branch and 'origin/master' have diverged, how to 'undiverge' branches'?

Somehow my master and my origin/master branch have diverged. I actually don't want them to diverge. How can I view these differences and merge them?
Frank's user avatar
  • 18.4k
183 votes
17 answers
86k views

How to get default Git branch?

My team alternates between usage of dev and master as default branch for several repos and I would like to write a script that checks for the default branch when entering a directory. When pull ...
random-forest-cat's user avatar
2331 votes
20 answers
878k views

Showing which files have changed between two revisions

I want to merge two branches that have been separated for a while and wanted to know which files have been modified. Came across this link: http://linux.yyz.us/git-howto.html (moved to web.archive.org)...
johannix's user avatar
  • 29.2k
771 votes
11 answers
352k views

How do you stop tracking a remote branch in Git?

How do you stop tracking a remote branch in Git? I am asking to stop tracking because in my concrete case, I want to delete the local branch, but not the remote one. Deleting the local one and ...
Jason Cohen's user avatar
  • 81.3k
757 votes
14 answers
312k views

Set up git to pull and push all branches

I'd like to push and pull all the branches by default, including the newly created ones. Is there a setting that I can define for it? Otherwise, when I add a new branch, locally and I want to pull ...
lprsd's user avatar
  • 84.3k
477 votes
12 answers
210k views

Show just the current branch in Git

Is there a Git command equivalent to: git branch | awk '/\*/ { print $2; }'
Ollie Saunders's user avatar
310 votes
4 answers
239k views

Difference between git checkout --track origin/branch and git checkout -b branch origin/branch

Does anybody know the difference between these two commands to switch and track a remote branch? git checkout -b branch origin/branch git checkout --track origin/branch I think both keep track of the ...
yorch's user avatar
  • 7,150
100 votes
4 answers
14k views

Rebasing a branch including all its children

I have the following Git repository topology: A-B-F (master) \ D (feature-a) \ / C (feature) \ E (feature-b) By rebasing feature branch I expected to rebase the whole ...
Tomasz Nurkiewicz's user avatar
719 votes
14 answers
278k views

How is a tag different from a branch in Git? Which should I use, here?

I am having some difficulty understanding how to use tags versus branches in git. I just moved the current version of our code from cvs to git, and now I'm going to be working on a subset of that ...
Bialecki's user avatar
  • 30k
3075 votes
31 answers
4.3m views

`git fetch` a remote branch

The remote repository contains various branches such as origin/daves_branch: $ git branch -r origin/HEAD -> origin/master origin/daves_branch origin/master How do I switch to daves_branch in the ...
David's user avatar
  • 34.8k
35 votes
4 answers
26k views

Vendor Branches in Git

A Git project has within it a second project whose content is being worked on independently. Submodules cannot be used for the smaller, as even the subproject must be included when users attempt to ...
SamGoody's user avatar
  • 13.7k
8 votes
1 answer
12k views

unknown option `allow-unrelated-histories'

I have two repos: Market and Android. When I merge Android to Market use these steps: cd market git remote add android ../android git fetch android git merge --allow-unrelated-histories android/...
LF00's user avatar
  • 27k
344 votes
16 answers
73k views

Branch descriptions in Git

Is there a way in Git to have a 'description' for branches? While I try to use descriptive names, working for a while on a single branch sometimes dampens my memory of why I made some of the other ...
Noufal Ibrahim's user avatar
595 votes
10 answers
290k views

Using Git, show all commits that are in one branch, but not the other(s)

I have an old branch, which I would like to delete. However, before doing so, I want to check that all commits made to this branch were at some point merged into some other branch. Thus, I'd like to ...
sircolinton's user avatar
  • 6,516
287 votes
10 answers
275k views

How to get the changes on a branch in Git

What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is: git log $(git merge-base HEAD branch)..branch The ...
Greg Hewgill's user avatar
427 votes
7 answers
185k views

How can I search Git branches for a file or directory?

In Git, how could I search for a file or directory by path across a number of branches? I've written something in a branch, but I don't remember which one. Now I need to find it. Clarification: I'...
Peeja's user avatar
  • 13.7k
346 votes
4 answers
229k views

Forking vs. Branching in GitHub

I'd like to know more about the advantages and disadvantages of forking a github project vs. creating a branch of a github project. Forking makes my version of the project more isolated from the ...
reprogrammer's user avatar
  • 14.3k
470 votes
16 answers
434k views

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's user avatar
  • 153k
233 votes
6 answers
108k views

git working on two branches simultaneously

I have a project with many branches. I would like to work on several branches simultaneously without switching back and forth with git checkout. Is there any way I can do that besides copying the ...
name's user avatar
  • 5,075
292 votes
4 answers
101k views

Can I make fast forwarding be off by default in git?

I can't really ever think of a time when I would use git merge rather than git rebase and not want to have a commit show up. Is there any way to configure git to have fast forwarding off by default? ...
Jason Baker's user avatar
1350 votes
7 answers
748k views

What are some examples of commonly used practices for naming git branches? [closed]

I've been using a local git repository interacting with my group's CVS repository for several months, now. I've made an almost neurotic number of branches, most of which have thankfully merged back ...
skiphoppy's user avatar
  • 97.5k
697 votes
10 answers
154k views

How do I merge my local uncommitted changes into another Git branch?

How can I do the following in Git? My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a ...
solsberg's user avatar
  • 7,875
847 votes
5 answers
212k views

View a file in a different Git branch without changing branches

Is it possible to open a file in a git branch without checking out that branch? How? Essentially I want to be able to open a file in my github pages branch without switching branches all the time. I ...
Schneems's user avatar
  • 14.9k
215 votes
5 answers
143k views

Reordering of commits

I'm currently working on a branch and want some commits to merge into other branches: a-b-c-d-e-f-g (branchA) / --o-x-x-x-x-x-x-x-x-x-x (master) \ x-x-x-x-x (branchB) (Letters denote ...
Peter's user avatar
  • 2,151
182 votes
3 answers
102k views

git shallow clone (clone --depth) misses remote branches

After cloning a remote repository it does not show any remote branch by -a option. What could be the problem? How to debug it? In this snippet two of the remote branches are not shown: $ git clone --...
minghua's user avatar
  • 5,971

1
2 3 4 5
16