diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_bWVyY3VyaWFsL2xvY2FscmVwby5weQ==..d9569d1f0d2d92165125559569db054e4c4d4b2b_bWVyY3VyaWFsL2xvY2FscmVwby5weQ== 100644
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -100,7 +100,9 @@
 urlerr = util.urlerr
 urlreq = util.urlreq
 
-RE_SKIP_DIRSTATE_ROLLBACK = re.compile(b"^(dirstate|narrowspec.dirstate).*")
+RE_SKIP_DIRSTATE_ROLLBACK = re.compile(
+    b"^((dirstate|narrowspec.dirstate).*|branch$)"
+)
 
 # set of (path, vfs-location) tuples. vfs-location is:
 # - 'plain for vfs relative paths
@@ -2671,6 +2673,13 @@
         # strip" to pick a working copy destination on `hg rollback`
         if self.currentwlock() is not None:
             ds = self.dirstate
+            if ds.branch() == b'default':
+                # force a file to be written if None exist
+                ds.setbranch(b'default')
+            # we cannot simply add "branch" to `all_file_names` because branch
+            # is written outside of the transaction control. So we need to
+            # backup early.
+            tr.addbackup(b"branch", hardlink=True, location=b'plain')
 
             def backup_dirstate(tr):
                 for f in ds.all_file_names():
@@ -2685,7 +2694,6 @@
     def _journalfiles(self):
         return (
             (self.svfs, b'journal'),
-            (self.vfs, b'journal.branch'),
             (self.vfs, b'journal.desc'),
         )
 
@@ -2694,9 +2702,6 @@
 
     @unfilteredmethod
     def _writejournal(self, desc):
-        self.vfs.write(
-            b"journal.branch", encoding.fromlocal(self.dirstate.branch())
-        )
         self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc))
 
     def recover(self):
@@ -2799,18 +2804,6 @@
                     self.dirstate.setparents(self.nullid)
                     self.dirstate.clear()
 
-            try:
-                branch = self.vfs.read(b'undo.branch')
-                self.dirstate.setbranch(encoding.tolocal(branch))
-            except IOError:
-                ui.warn(
-                    _(
-                        b'named branch could not be reset: '
-                        b'current branch is still \'%s\'\n'
-                    )
-                    % self.dirstate.branch()
-                )
-
             parents = tuple([p.rev() for p in self[None].parents()])
             if len(parents) > 1:
                 ui.status(
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_bWVyY3VyaWFsL3RyYW5zYWN0aW9uLnB5..d9569d1f0d2d92165125559569db054e4c4d4b2b_bWVyY3VyaWFsL3RyYW5zYWN0aW9uLnB5 100644
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -692,6 +692,10 @@
         if entries:
             return False
         for e in self._backupentries:
+            if e[0] == b'plain' and e[1] == b'branch':
+                # XXX integrate branch to the transaction and get rid of this
+                # aberration
+                continue
             if e[1]:
                 return False
         return True
@@ -701,7 +705,9 @@
         assert self._can_quick_abort(entries)
         tmp_files = [e for e in self._backupentries if not e[1]]
         for vfs_id, old_path, tmp_path, xxx in tmp_files:
-            assert not old_path
+            # XXX integrate branch to the transaction and get rid of this
+            # aberration
+            assert not old_path or old_path == b'branch'
             vfs = self._vfsmap[vfs_id]
             try:
                 vfs.unlink(tmp_path)
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_dGVzdHMvdGVzdC1mbmNhY2hlLnQ=..d9569d1f0d2d92165125559569db054e4c4d4b2b_dGVzdHMvdGVzdC1mbmNhY2hlLnQ= 100644
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -104,7 +104,6 @@
   .hg/requires
   .hg/undo
   .hg/undo.backupfiles
-  .hg/undo.branch
   .hg/undo.desc
   .hg/wcache
   .hg/wcache/checkisexec (execbit !)
@@ -142,7 +141,6 @@
   .hg/store/requires
   .hg/store/undo
   .hg/store/undo.backupfiles
-  .hg/undo.branch
   .hg/undo.desc
   .hg/wcache
   .hg/wcache/checkisexec (execbit !)
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_dGVzdHMvdGVzdC1oYXJkbGlua3MudA==..d9569d1f0d2d92165125559569db054e4c4d4b2b_dGVzdHMvdGVzdC1oYXJkbGlua3MudA== 100644
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks.t
@@ -257,7 +257,6 @@
   2 r4/.hg/store/undo.backup.phaseroots
   2 r4/.hg/store/undo.backupfiles
   2 r4/\.hg/undo\.backup\.dirstate (re)
-  2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
   2 r4/.hg/wcache/checkisexec (execbit !)
   2 r4/.hg/wcache/checklink-target (symlink !)
@@ -312,7 +311,6 @@
   2 r4/.hg/store/undo.backup.phaseroots
   2 r4/.hg/store/undo.backupfiles
   2 r4/\.hg/undo\.backup\.dirstate (re)
-  2 r4/.hg/undo.branch
   2 r4/.hg/undo.desc
   2 r4/.hg/wcache/checkisexec (execbit !)
   2 r4/.hg/wcache/checklink-target (symlink !)
diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_dGVzdHMvdGVzdC1pbmhlcml0LW1vZGUudA==..d9569d1f0d2d92165125559569db054e4c4d4b2b_dGVzdHMvdGVzdC1pbmhlcml0LW1vZGUudA== 100644
--- a/tests/test-inherit-mode.t
+++ b/tests/test-inherit-mode.t
@@ -94,7 +94,6 @@
   00600 ./.hg/store/requires
   00660 ./.hg/store/undo
   00660 ./.hg/store/undo.backupfiles
-  00660 ./.hg/undo.branch
   00660 ./.hg/undo.desc
   00770 ./.hg/wcache/
   00711 ./.hg/wcache/checkisexec
@@ -151,7 +150,6 @@
   00660 ../push/.hg/store/requires
   00660 ../push/.hg/store/undo
   00660 ../push/.hg/store/undo.backupfiles
-  00660 ../push/.hg/undo.branch
   00660 ../push/.hg/undo.desc
   00770 ../push/.hg/wcache/
 
diff --git a/tests/test-rollback.t b/tests/test-rollback.t
index fb4a716db129c2ceb5b1eeeff88f9fefc935927e_dGVzdHMvdGVzdC1yb2xsYmFjay50..d9569d1f0d2d92165125559569db054e4c4d4b2b_dGVzdHMvdGVzdC1yb2xsYmFjay50 100644
--- a/tests/test-rollback.t
+++ b/tests/test-rollback.t
@@ -42,5 +42,4 @@
   $ cat .hg/last-message.txt ; echo
   modify a
 
-Test rollback of hg before issue 902 was fixed
 
@@ -46,12 +45,5 @@
 
-  $ hg commit -m "test3"
-  $ hg branch test
-  marked working directory as branch test
-  (branches are permanent and global, did you want a bookmark?)
-  $ rm .hg/undo.branch
-  $ hg rollback
-  repository tip rolled back to revision 0 (undo commit)
-  named branch could not be reset: current branch is still 'test'
-  working directory now based on revision 0
+working dir unaffected by rollback: do not restore dirstate et. al.
+  $ hg branch test --quiet
   $ hg branch
   test
@@ -56,7 +48,5 @@
   $ hg branch
   test
-
-working dir unaffected by rollback: do not restore dirstate et. al.
   $ hg log --template '{rev}  {branch}  {desc|firstline}\n'
   0  default  add a again
   $ hg status
@@ -82,7 +72,7 @@
   $ hg update bar
   1 files updated, 0 files merged, 1 files removed, 0 files unresolved
   (activating bookmark bar)
-  $ cat .hg/undo.branch ; echo
+  $ cat .hg/undo.backup.branch
   test
   $ hg log -G --template '{rev}  [{branch}] ({bookmarks}) {desc|firstline}\n'
   o  2  [test] (foo) add b