how to make fork on github updated - github

I found good project (boilerplate), which I am going to use as starting point for my project.
And I forked it.
git clone https://github.com/fork.git forkdirectory # clone my fork to my local PC
git branch mybranch # create new branch for my specialities, which will be different from boilerplate
git checkout steklo # change the branch, which I will work on by default
Then I make some changes and check that they appear in my fork
git add . # add all changes for commit
git commit -m"commit comments" # make commit
git push -u origin mybranch # push changes to mybranch
I tested that for next changes I can just do shorter
git push
But what should I do when I will see that initial boilerplate updated?
1) How to apply all updates to my fork?
2) And then how to apply all updates from my fork to my local clone?

I think i understand your confusion about it,
This process steps are
Fork the repository.
Update the repository.
Create a pull request
Now Owner of the repository sees, if your request is valid, he merge the request.
You've already completed first two steps, now you only need to submit a pull request.
Goto Pull requests of your forked repo
Create a new pull request
Owner will see if it is valid then he will merge your pull request to the repo
that's all
Cheers :)

Related

how to move master branch to main branch on github

I have a master branch and a main branch in git-hub. This was not intentional I realized that I have been pushing with master so everything went to master branch. However git-hub is now using main instead of master as first position. How can I move my master branch into main branch?
There are multipe ways to achieve this, but with pure git it can be done as follows:
#Change to the main branch
git checkout main
#Rebase the main branch on top of the current master. In easy words, go to the last point the two branches have in common, then add all the changes master did in the meanwhile and then add the changes done to main. If main is empty this is equivalent to
# git checkout master; git branch -D main; git checkout -b main
#which deletes the current main and then copies master over to main
git rebase master
# push back to GitHub (--force, because rabse does not add a commit, but changes the status, so push will be rejected without it)
git push --force
You can delete or rename a branch through the github web interface by visiting
https://github.com/YourName/YourRepo/branches
At time of writing you can access that page from the front page of your repository through the branches link:
And you can click the writing implement buttons to rename their associated branch:
It is worth noting that deleting and renaming branches through github is just as potentially destructive as doing it with CLI git or a GUI git client. You can of course re-push branches from your local clone, but you should make sure that clone is up to date before proceeding if you feel unsure.
Create a PR from master to main in the GitHub Webinterface.
If you want to do it local:
git checkout main
git merge master
git push
Set local master to track remote main:
git branch --set-upstream-to origin/main master
For first pull it will show error refusing to merge unrelated histories so you can pull with git pull origin main --allow-unrelated-histories
Push it into the main branch in GitHub.

How to keep a GitHub fork up to date without a merge commit or using CLI?

The normal GitHub flow to contribute to a repo is to create a fork of the upstream, clone a local copy where you make changes, then push back up to your fork and then create a PR to have your changes merged into upstream.
But if upstream changes after that, how do you update your fork without creating a merge commit (and also without using the git CLI)?
I already know how to do this in a way that will create a merge commit or which depend on the git command line interface. This question is specifically about using the GitHub.com website or GitHub Desktop application only (no CLI).
Since this is a very common workflow it seems like there should be some simple way to do it using the GitHub GUI.
To reiterate: any answers that use the CLI or create a merge commit (e.g. this way) will not be answering this question since I'm explicitly looking for a non-CLI solution.
without a merge commit or using CLI?
Not directly with GitHub web UI alone, since it would involve rebasing your PR branch on top of upstream/master
So in short: no.
But in less short... maybe, if you really want to try it.
Rebasing through GitHub web UI is actually possible, since Sept. 2016, ...
if you are the maintainer of the original repo, wanting to integrate a PR branch
if none of the replayed commit introduces a conflict
(This differs from GitHub Desktop, which, since June 5th 2019 does support rebasing. But that is a frontend to Git CLI, like other tools provide. For example GitKraken and interactive rebase)
So a convoluted workaround would be:
to fetch, then push upstream/master to the master branch of your own fork (a CLI operation, but more on that below)
change the base branch of your current PR to master (so a PR within the same repository: your own fork), provided you haven't pushed to master.
Meaning: master in your fork represents the updated upstream/master, with upstream being the original repository that you have forked.
Since you are the owner of that repository (your fork), GitHub can then show you if you can rebase said branch to the base branch of the PR (master), but only if there is no conflict.
finally, change the base branch again, to <originalRepo>/master (which is the intended target of your PR)
The very first step is typically done through command line, but... there might be a trick to do it (update upstream master in your fork) through web UI: see "Quick Tip: Sync a Fork with the Original via GitHub’s Web UI" by Bruno Skvorc
In short, it involves:
creating a new branch from your current master (which would be at upstream/master at the time you forked the original repository)
Making a PR with that new branch and <originalRepo/master>
doing a base switch before creating the PR
That is the step which artificially forces upstream/master to be refreshed
You can the create and merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards): the merge will be trivial: no merge commit.
The end result is: your own master branch (in your fork) updated with upstream/master (the master branch of the original repository)!
You can then resume the steps I describe above, and change the base of your current PR to your own (now refreshed) master branch, and see if you can rebase it!
This is feasible with GitHub Desktop since version 1.0.7 considering the following:
If the current branch does not have any commits ahead upstream (the original repo of the fork), the new commits can be pulled without creating a new merge commit
In GitHub Desktop:
Clone your repository from File > Clone Repository
Fetch origin, which will automatically fetch the upstream as well
Go to Branches by clicking on where it says Current Branch
Click on Choose a branch to merge into <branch> at the bottom
Search for upstream/<branch>, then click Merge upstream/<branch> into <branch>
Push to origin, et voilà!
Otherwise, ff the current branch has commits ahead of the fork, then of course one has to create a merge commit or rebase and force push. For rebasing which might be more preferable, do the following:
In GItHub Desktop, go to Branch from menu, then Rebase Current Branch
Search for upstream/<branch>, then click Start Rebase
Solve any conflicts that have occurred from the rebase
Force push to origin. You will get a warning for this for obvious reasons.
For avoiding force-pushing to your work when your current branch is both ahead and behind its upstream counterpart, either create a new merge commit or:
Make a new branch based with all your changes
If needed, reset the original branch to its original state (before it diverged from the original repo)
Perform the steps from the first scenario and merge your changes into your branch.
And yes, it seems that pulling via the GitHub website from the original repo without creating a pull request and merge commit is not possible at this moment.
Demo GIF for first scenario: https://imgur.com/a/8wci2yf
Some GitHub issues related to this:
Add an upstream to forked repositories
multi-remote support in Desktop
Update
Note: Non-CLI based approach that might help:
Is there a way to make GitHub Desktop rebase a branch against master?
The only key here is doing a rebase, so the above answer should help.
CLI way (which is easier and using git, so it should be more comprehensive by default)
There are some practices that you should use to avoid this.
Don't work on the master branch in your fork.
$ git clone <your fork>
$ git checkout -b feature_branch
You can work in your feature_branch and then raise a Pull Request.
Once your changes are merged in the upstream master, you can pull from upstream to your origin. Since the master on upstream will have your commits sitting neatly on top of it, there won't be a merge commit.
$ git checkout master
$ git pull upstream master
$ git push origin master
In the case, where the maintainer has diverged from the master that you have in your fork, that is, it's not linear any more, you need to pull a fresh copy of it. That should not be a problem as your changes are already in the upstream.
If the master in upstream has moved ahead while you were working on your PR, then you can rebase on you feature_branch.
$ git checkout master
$ git pull upstream master
$ git push origin master
$ git checkout feature_branch
$ git rebase master
Please refer to this document for detailed reference: Fork and pull request workflow

Pull fork and submit pull request

I am working with GitHub and want to submit a pull request. When I fork the repository I don't see my changes I'm guessing because it never asked me where to link the repository to. How do I link the forked repo to a location on my personal computer for the pull request? This is for an interview and with the code done I don't know where (or how) to put it.
I'm the first to oppose noise but I don't know what other exchange site to post on. I'll close it if I'm pointed somewhere else and it doesn't get closed first.
If you have cloned the original repo locally, you can:
make sure you have a fork on GitHub (you seem to have one, where you say you don't see your changes, which is expected since you haven't push them yet)
declare that fork as your new origin
That is
cd /path/to/my/local/repo
git remote rename origin upstream
git remote add origin https://github.com/<myGitHubAccount>/<reponame.git>
Don't forget to add your changes, commit and push:
git checkout -b aNewBranch
git add .
git commit -m "Fix done in a new branch for PR (Pull Request)"
git push -u origin aNewBranch
From there, you can go to https://github.com/<myGitHubAccount>/<reponame.git>, switch to aNewBranch, and click "Make a Pull Request"

Github pull without a pull request

On github, how is it possible for the owner of an original repository to pull the changes that were made in a fork by another user, without a pull request? Or anyway include the fork's changes into the original repository, maintaining information about the fork's author?
Should I clone the fork and then push it to the original repository?
Or I could copy them manually, but that wouldn't be fair at all, because the project would lose any information about the fork's changes author.
You would use the normal distributed workflow of Git here. That is, add the other repository as a second remote to your local repository, and then simply merge their changes in.
git remote add others-fork https://github.com/otheruser/fork.git
git fetch others-fork
git checkout master
git merge others-fork/master
This would merge the changes from their master into your local master. Afterwards, you can push your changes to publish their commits in your repository.

Is there a quick way to shift to a fork in github?

The following happens to me from time to time:
clone something from github
discover something I want to fix.
want to offer it back.
Go make a fork
clone my fork
manually merge my changes to the fork
open a pull request
Somehow, it seems to me that there should be a simpler way to get from 'I've got local changes in a local branch' to 'I've got changes in a fork I can submit a pull for.'
Is there?
Github has the hub gem for maniplating their API.
Secondarily ( and I think what you're looking for) you can add a second remote to your original repo like
git remote add myfork git://github.com/defunkt/hub.git # for the case of hub
and then
git push -u myfork branchname
to push branchname up to your fork from the original repo. The -u flag sets that branches upstream to be your fork.