I've seen several answers about updating the fork with the commits of the upstream, but I haven't found how to update the entire repository.
I cloned a repo into my fork, made changes, commited, pushed, done.
In the meanwhile, other branches were created, deleted, etc.
Now I want to create a branch from a new created branch in the upstream, but I can't find it on my fork's GitHub UI for example, it's still showing the old ones.
How can I update this?
I already tried to fetch the upstream, no success.
EDIT: to make it easier to understand, I will give an example:
In original repo, it has a new created branch, let's say, "fancy-new-branch"
If I type git checkout fancy-new-branch, it switches to this branch, but in the original repo. But I want to be in my fork, so I can create a new branch for example "fancy-new-branch-fix" from "fancy-new-branch" I think I need to access "fancy-new-branch" from my fork, or am I wrong?
Thanks
I ended up deleting my fork, creating and cloning again. But I will keep up the question: isn't there an automatic way to update?
Related
I'd like to know how to proceed in GitHub where I could to be able to get the updates from the original repo but prevent opening a PR after each time I push a change made by myself?
The concept I want to apply this is to use a blog template for my GitHub pages. I'd like to get the feature for the future if the contributors would make any but at the same time, I'd like to prevent pushing anything to the original repo as a PR since those commits wouldn't include anything related to making a contribution to the project.
PRs aren't generated automatically, you need to explicitly create them from a branch.
You can fork a repo and work on it, and when needed, fetch and rebase from the original repo you forked from. As long as you don't explicitly use this repo to create PRs on the original repo, you should be fine.
EDIT - Adding some details as per the last comment:
Assume there's a repo called something owned by someone. You can start off by forking it to youruser using the GitHub UI. Then you can clone your fork and work on it:
git clone https://github.com/youruser/something.git
In order to get the recent changes from the original someone/something repo, you need to set it up as a remote. By convention you'd call this remote your "upstream", but you can really give it any name you choose:
git remote add upstream https://github.com/someone/something.git
Once you've added it as a remote, you can fetch from it and rebase on top of it:
git fetch upstream && git rebase upstream/main
(note that using the main branch is just an example. You can of course rebase on top of any branch in the remote repo)
I think it's not possible because when you clone or fork that repo, from that time, you start to add your own content to it since it's your personal blog. So you cannot keep getting the features from main repo. Maybe you can try rebase but I'm not sure if it works for this case. Or you can add those features to your repo by your own whenever you need them.
To be clear: I am NOT asking how to keep my fork up-to-date. I am asking a very different question, and the answer seems to be independent of GitLab or Github.
I'm curious as to why my fork doesn't need to be kept up-to-date? I have forked a project, and I have a local clone of the project with two remotes ("thetango", my fork, and "upstream", the main project). I have noticed that I don't ever really need to update my fork on either GitLab or GitHub.
I would have thought that when I pushed to create a PR (GitHub) or an MR (GitLab) the first error I would have received is that my fork is out-of-date and needs to be fast-forwarded. That never happens, which confuses me.
What git magic does GitLab and Github implement so that my fork doesn't need to be updated? Am I misunderstanding what a fork is?
When you create a pull request between your fork of a repository and a branch in the main repository, you're essentially proposing a merge between a given branch in your repository and a given branch in the main repository. The only branches which matter in that case are those two.
You may have other branches in your fork, such as the default branch and branches that include other work you're doing, but unless you're doing a pull request with one of them, how far ahead or behind they are from their corresponding branches in the main repository is irrelevant.
Now, if the branch you're creating a pull request from is far behind the one you want to merge into in the main repository, then the chance of merge conflicts increases. Therefore, it's prudent to keep your local repository up to date with the main repository if you're going to be creating pull requests, so that when you push that branch to make a PR, the branch you push is not substantially out of date.
One reason you may choose to keep your fork's main branch up to date is if you're doing independent development. For example, Git for Windows contains many Windows-specific patches which have not made it into mainline Git, so their repository is kept up to date because it's essentially an entire separate line of development.
I've accidentally deleted a branch on my github repository.
I've searched up for a solution, and tried the methods mentioned here and here, but because I never merged that branch into master - I don't see it in the reflog at all.
My only local working copy that still has that branch on it is unreachable for few days because of technical issues.
Is there any way to recover that deleted branch?
The quickest way remains to write to GitHub support: they do have access to the refleg of the GitHub repo, and can restore that branch for you.
Then a simple fetch would allow you to recover that same branch in your local repo.
If you are not working through GitHub(say BitBucket..) and the branch you have in your local does not lave the log for unmerged branches in reflog, then there are two options
1) find a team member who has last fetched from the repo and can access all the branches in his fetched repo. He can then transfer to each of the remote branch and push that particular code up to the repo. You can go back in your other workspaces/folders to see if you have fetched from any other feature branches and can do the same.
2) ask all other team members who are working on their local branch to push their code up the repo recreating the structure for (only live) branches.
This will be still incomplete as the restructuring will miss the commits after the last fetch till the current merge and the tree history will be modified in its refs . But at least it will avoid complete loss of code base and history.
I read all SO questions about this issue, and I still can't resolve it.
I am using TortoiseHg. I worked on a side-branch, and now I want to merge it back to the main branch. I pulled all changes made in both branches, updated to the main branch, and merged (and committed). But still when I try to push all this, I get the "abort:push creates new remote head" message.
I also tried (as was suggested in one of the questions in SO) to close the branch using the --close-branch option.
The only thing I did not try is to 'force' push.
Any suggestions? Or is force-pushing the only option?
Just for everyone else that runs into this problem.
What caused this problem for me were some local revisions on the default branch that I didn't push before I started to work on a new branch.
I had merged the latest revision I pulled for the default branch with my new branch, but these leaves your local changes to the default branch committed but un-pushed.
If you try to push them, it's not your new branch that is creating a remote head, it's the un-pushed revisions to the default branch that is creating a remote head.
When I stripped out those revision with hg strip -r 1234
hg push --new-branch
went perfect.
What put me on the right track was
hg heads
With showed I had two heads that both had the name of the default branch with different revision numbers.
I just tried a similar setup, and I get the same warning. Apparently, although the second head you are trying to push is closed, it is seen as another head during the push. And closing both heads does not seem to be pushable either.
You can force the push, it should be ok, but you could eventually get the same issue if you keep multiple heads on your visualization branch, like you already have with changesets 14 and 20. To solve the issue once and for all, I would instead suggest to merge both changesets (14 and 20) and reclose the final head.
Thanks for the answers, I definitely learned some new tricks.
What I ended up doing, is cloning an early revision from the remote repository, that is, a repository that doesn't have all the commits of my merges etc. I then pulled the change-sets, merged, and committed. Then the push finally succeeded.
It was basically the same steps I tried to do before, but apparently on the first (unsuccessful) trial I broke it down to more steps than were needed, and something went wrong at some point.
Try this solution,
Assumption. You have enough rights to close and create the branch in the remote
This happens because you are trying to rewrite the history. Just try hg push -f which will create two heads in the remote repo, which you might not
So the first login to your remote and close the branch, now come to your local and push using hg push -f. The necessary new branch will be created automatically with the original condition as it was before.
I've found a repository on GitHub I would like to fork - but not the current version.
I want to fork the repo as it was quite a few commits back - is this possible? The repo has not marked any releases, so I'm not sure how to do this. I could obviously copy the code as it was in that commit, but I would prefer to fork, as then I get the link back to the original repo.
You can only fork the current repository.
You can reset the forked repository's master branch to an earlier commit though, making it look like as if you had forked it at that point.
See: How can I rollback a github repository to a specific commit?
If you reset every branch, it effectively resets your repository to an earlier state of the original repository (with exception of branch-independent data, like configuration, hooks etc which are not reset). Since it's possible that not all branches contain the commit from the master branch, you might need to look up commits by date for each branch, to reset them to the last commit before the commit from which you want to fork.
I was also unable to do this using github, but Sourcetree handled it perfectly.
Switched to the desired branch.
Found the commit that I wanted as the head of my new branch and right clicked.
Selected "branch."
My commit was already selected.
Name this new branch, create, and push.
Can also be done by selecting the "branch" button.
You then select the commit that you want as your new head, give it a name, and create it.