You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2019/02/12 22:20:19 UTC

[OT][GIT help] How to restore a branch in a github fork

I have a github fork of a 3rd party repo.

Unfortunately I deleted a branch for which I wish to provide patches.

Anyone know how to restore/recreate an upstream branch in a Github fork?

I cannot destroy and recreate the fork as it has some outstanding PRs.

I suppose I could create a second fork, but that seems a bit
unnecessary - if only I could recover the missing branch.

Any Git gurus here?

S.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by Marcelo Vanzin <va...@cloudera.com.INVALID>.
On Tue, Feb 12, 2019 at 5:03 PM sebb <se...@gmail.com> wrote:
> > Interesting, never seen that. Even just looked at one of my forks and
> > couldn't find it...
>
> It appears when I click on branches.
> This shows Overview/Yours/Active/Stale/All branches

Ah, I see. Guess I've never used that view.

IMO it doesn't really make a whole lot of sense to have the upstream
repo branches in your fork, since they're not kept in sync after the
fork. e.g. https://github.com/vanzin/spark/tree/master is a few years
behind the current master... I never actually use my own fork's
master, it's just there because github created it when I forked.

But hey, maybe there's some workflow I'm not familiar with. Whatever works.

-- 
Marcelo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by sebb <se...@gmail.com>.
On Wed, 13 Feb 2019 at 00:47, Marcelo Vanzin
<va...@cloudera.com.invalid> wrote:
>
> On Tue, Feb 12, 2019 at 4:44 PM sebb <se...@gmail.com> wrote:
> >
> > On Wed, 13 Feb 2019 at 00:31, Marcelo Vanzin
> > <va...@cloudera.com.invalid> wrote:
> > >
> > > On Tue, Feb 12, 2019 at 4:25 PM sebb <se...@gmail.com> wrote:
> > > > It's shown as one of 'my' branches, but I guess I can live with that.
> > >
> > > Not sure what you mean by that?
> >
> > GitHub lists the restored branch under the tab 'Yours', along with a
> > couple of branches I created that don't exist in the upstream.
>
> Interesting, never seen that. Even just looked at one of my forks and
> couldn't find it...

It appears when I click on branches.
This shows Overview/Yours/Active/Stale/All branches

> --
> Marcelo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by Marcelo Vanzin <va...@cloudera.com.INVALID>.
On Tue, Feb 12, 2019 at 4:44 PM sebb <se...@gmail.com> wrote:
>
> On Wed, 13 Feb 2019 at 00:31, Marcelo Vanzin
> <va...@cloudera.com.invalid> wrote:
> >
> > On Tue, Feb 12, 2019 at 4:25 PM sebb <se...@gmail.com> wrote:
> > > It's shown as one of 'my' branches, but I guess I can live with that.
> >
> > Not sure what you mean by that?
>
> GitHub lists the restored branch under the tab 'Yours', along with a
> couple of branches I created that don't exist in the upstream.

Interesting, never seen that. Even just looked at one of my forks and
couldn't find it...

-- 
Marcelo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by sebb <se...@gmail.com>.
On Wed, 13 Feb 2019 at 00:31, Marcelo Vanzin
<va...@cloudera.com.invalid> wrote:
>
> On Tue, Feb 12, 2019 at 4:25 PM sebb <se...@gmail.com> wrote:
> > It's shown as one of 'my' branches, but I guess I can live with that.
>
> Not sure what you mean by that?

GitHub lists the restored branch under the tab 'Yours', along with a
couple of branches I created that don't exist in the upstream.

> The branches in your fork don't really have any relation to the
> original repo. They may have the same name and even reference the same
> commit, but you can update your repo to change that without affecting
> the original repo. So all of the branches in your fork are "your"
> branches.

OK

> --
> Marcelo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by Marcelo Vanzin <va...@cloudera.com.INVALID>.
On Tue, Feb 12, 2019 at 4:25 PM sebb <se...@gmail.com> wrote:
> It's shown as one of 'my' branches, but I guess I can live with that.

Not sure what you mean by that?

The branches in your fork don't really have any relation to the
original repo. They may have the same name and even reference the same
commit, but you can update your repo to change that without affecting
the original repo. So all of the branches in your fork are "your"
branches.

-- 
Marcelo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by sebb <se...@gmail.com>.
On Wed, 13 Feb 2019 at 00:08, Marcelo Vanzin
<va...@cloudera.com.invalid> wrote:
>
> On Tue, Feb 12, 2019 at 3:58 PM sebb <se...@gmail.com> wrote:
> > Deleted from local and remote.
> > But it still exists in the upstream from which the Github repo was forked
> >
> > It is still in the upstream source - that is a 3rd party repo
> > How can I restore it from there?
>
> It's easy then:
>
> - make sure you have the upstream repo as a remote (use "git remote
> add" if it's not there)
> - git fetch <original_remote>
>
> Create your local branch:
> - git checkout -b <local_branch> <original_remote>/<branch_name>
>
> Push your local branch to your remote:
> - git push <your_remote> HEAD:<branch_name>
>

Thanks very much, that has restored the branch on my GitHub.

It's shown as one of 'my' branches, but I guess I can live with that.

> --
> Marcelo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by Marcelo Vanzin <va...@cloudera.com.INVALID>.
On Tue, Feb 12, 2019 at 3:58 PM sebb <se...@gmail.com> wrote:
> Deleted from local and remote.
> But it still exists in the upstream from which the Github repo was forked
>
> It is still in the upstream source - that is a 3rd party repo
> How can I restore it from there?

It's easy then:

- make sure you have the upstream repo as a remote (use "git remote
add" if it's not there)
- git fetch <original_remote>

Create your local branch:
- git checkout -b <local_branch> <original_remote>/<branch_name>

Push your local branch to your remote:
- git push <your_remote> HEAD:<branch_name>


-- 
Marcelo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by sebb <se...@gmail.com>.
On Tue, 12 Feb 2019 at 22:34, Marcelo Vanzin
<va...@cloudera.com.invalid> wrote:
>
> If:
>
> - you deleted the branch from the remote
>
> Just push your local branch to the remote.
>
> - you deleted the branch from the local repo only
>
> Just checkout the remote branch again. If you had local changes that
> are not in the remote, continue below.
>
> - you deleted the branch from local and it did not exist in the
> remote, or you also deleted from the remote

Deleted from local and remote.
But it still exists in the upstream from which the Github repo was forked

That is the branch I want to restore.

> Check "git reflog" and see if the commits to the deleted branch still
> exist. If they do you can just "checkout" them again.

But how do I restore the branch in my Github fork?

> - if none of the above applies, well, I think you just lost the code.

It is still in the upstream source - that is a 3rd party repo
How can I restore it from there?

> On Tue, Feb 12, 2019 at 2:29 PM sebb <se...@gmail.com> wrote:
> >
> > I have a github fork of a 3rd party repo.
> >
> > Unfortunately I deleted a branch for which I wish to provide patches.
> >
> > Anyone know how to restore/recreate an upstream branch in a Github fork?
> >
> > I cannot destroy and recreate the fork as it has some outstanding PRs.
> >
> > I suppose I could create a second fork, but that seems a bit
> > unnecessary - if only I could recover the missing branch.
> >
> > Any Git gurus here?
> >
> > S.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
>
>
> --
> Marcelo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [OT][GIT help] How to restore a branch in a github fork

Posted by Marcelo Vanzin <va...@cloudera.com.INVALID>.
If:

- you deleted the branch from the remote

Just push your local branch to the remote.

- you deleted the branch from the local repo only

Just checkout the remote branch again. If you had local changes that
are not in the remote, continue below.

- you deleted the branch from local and it did not exist in the
remote, or you also deleted from the remote

Check "git reflog" and see if the commits to the deleted branch still
exist. If they do you can just "checkout" them again.

- if none of the above applies, well, I think you just lost the code.

On Tue, Feb 12, 2019 at 2:29 PM sebb <se...@gmail.com> wrote:
>
> I have a github fork of a 3rd party repo.
>
> Unfortunately I deleted a branch for which I wish to provide patches.
>
> Anyone know how to restore/recreate an upstream branch in a Github fork?
>
> I cannot destroy and recreate the fork as it has some outstanding PRs.
>
> I suppose I could create a second fork, but that seems a bit
> unnecessary - if only I could recover the missing branch.
>
> Any Git gurus here?
>
> S.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>


-- 
Marcelo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org