Sync my Pull request with someone else commit some changes - Github - github

I sent a PR and someone else made some changes so it has 3 more commits and now I need to sync that PR with my local to continue working on some changes. How could I do to sync my local with the PR. Thanks

A pull request is basically just a designated branch on your fork of the repository. Update that branch (by rebasing its commits on top of those new commits) and the pull request will automatically update to show these changes.
First, you need access to the additional commits in your own fork of the project. To do so, you can add the upstream repository as an additional remote and fetch the commits from there:
git remote add <new-remote-name> <upstream-url.git>
git fetch <new-remote-name> <upstream-branch>
Then you can rebase your changes on top of the upstream changes:
git checkout <your-pr-branch>
git rebase <new-remote-name>/<upstream-branch>
git push <origin> <your-pr-branch>

You need to rebase your branch to reflect all the merged work of others in your PR. Here is how you can do this:
Let's say upstream is the name of the remote repository which you have forked, and origin is the name of your forked repository.
git pull --rebase upstream master
git push origin master
There can be merge conflicts sometime during rebasing. In that case, check the files in which conflicts are there using:
git status
The name of the files which are in red color are the files having conflicts. Resolve the conflict manually. After resolving, add the files using:
git add <filename> or //for each conflicted file
git add --all //to add all files at once
Once again check the status using the git status command. If all the files are shown in green that means they are resolved and you can now continue your rebase. Run the below command for continuing your rebase:
git rebase --continue
Once done, simply push the changes to your forked repo using:
git push -f origin master
Note: In case, you have not set the remote url of your upstream and origin, add them using following commands:
git remote add upstream <upstream-url>
git remote add origin <origin-url>

Related

How to keep git fork up to date

I have tried
git remote add upstream https://github.com/CSSEGISandData/COVID-19.git
and I get "not a git repository". I just want to keep the fork in sync with the root or whatever it's called. There's a new file added for each day and I want to not have to delete all of my files and refork. I somehow managed to do it once but for some reason I am now apparently committing to the original or something, I have no absolutely no clue what I'm doing.
First, make sure you are working from a clone of your fork:
git clone https://github.com/[your git account]/[your git repo].git
That will make a local copy of the fork that was made on github.
To keep your fork up to date with the upstream changes, you need to add upstream as a remote, which is what it appears you are trying to do (make sure you are in the directory for the local copy of the repo, or git will complain):
cd [local clone directory]
git remote add upstream https://github.com/CSSEGISandData/COVID-19.git
Then fetch upstream:
git fetch upstream
Then check out your master branch, and merge the upstream version:
git checkout master
git merge upstream/master
Note that git checkout master means the master from your fork, which we're assuming is missing some changes from the upstream source, which is then being merged in on the next line.

How to create a second distinct pull request from a GitHub fork?

I have a GitHub fork. I used it to create a pull request against upstream.
I'm trying to work on a second pull request. I don't want the second pull request to cross pollinate into the first pull request.
How do I configure things so I can work on the second pull request without contaminating the first full request?
The obvious answer (for me) is to create a second clone. GitHub does not allow that.
The next obvious answer (for me) is to create a branch. But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Here's the error when attempting to create a branch. Notice the pull fails, and I am not allowed to set its origin to my fork:
$ git checkout -b arm-aes
Switched to a new branch 'arm-aes'
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> arm-aes
Now try to fix it:
$ git remote -v
origin https://github.com/noloader/botan.git (fetch)
origin https://github.com/noloader/botan.git (push)
upstream https://github.com/randombit/botan (fetch)
upstream https://github.com/randombit/botan (push)
$ git branch --set-upstream-to=https://github.com/noloader/botan.git
error: the requested upstream branch 'https://github.com/noloader/botan.git' does not exist
...
$ git branch --set-upstream-to=https://github.com/noloader/botan
error: the requested upstream branch 'https://github.com/noloader/botan' does not exist
...
But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Sure it does:
git fetch upstream
git checkout -b newbranch upstream/master
Make sure you have a git remote upstream referencing the original repository (the one you have forked).
git remote add upstream https://github.com/<user>/<repo>

Merging changes head branch to master branch in git

I am currently making a project in eclipse.I made changes in head branch and as well as in master branch.I want to merge those changes and push them to remote repository.Please tell me the correct steps so i merge both branches and push the changes to remote repository without getting non fast forward warning.
I am currently making a project in eclipse.I made changes in head branch and as well as
in master branch.
Normally when people refer to "head" they are talking about HEAD, which is not actually a branch but a reference to the "tip" of the currently checked out branch. So if you
git clone foo
cd foo
git checkout bar
assuming bar is a branch, then HEAD would refer to the "tip" or last commit of the bar branch.
If you are getting a non fast forward warning on a push, changes have been made to the remote repository. You to bring those changes into your local branch before you can push.
This is because git requires merge conflicts be resolved in the local repository, not the (usually shared) remote repository. To bring those changes to your local repository you will need to execute a pair of commands; git fetch ... and git merge ... results in a merge commit, which some prefer -- while git fetch ... and git rebase ... if merging the changes without a merge commit is preferred. Note that git pull ... is the same as git fetch ... and git merge ... and git pull --rebase ... is the same as git fetch ... and git rebase ....
Which ever way your prefer, once you get the changes to your local repository (and resolve any conflicts there may be) you will be ready to push.

I've fork a repo in github. How could I fetch all changes from the original repo?

In this case, I've fork grocery-CRUD repo from github.
I make some changes, and submit a pull request.
The author accept it, and do some other modification.
How could I fetch the newest modification to my grocery-CRUD repo?
Thanks
You add his repo as a remote (git remote add <his repo> <repo spec>).
Then, you pull changes from his repo (git pull <his repo>)
Then, you push the changes to your repo (git push origin)
git pull git://github.com/scoumbourdis/grocery-crud.git
This will fetch the changes and merge them with your current branch in your local repository.
If you want to get it on your remote you need to push
git push origin

cannot see committed changes in repo

I have staged my files like this
git add mydir
git add mydir/myfile
and then pushed them to my repo
git remote add origin https://github.com/usename/myrepo.git
git push origin master
When I look at git status -s it says my files have been added, but I cannot see them in my actual repository. Does anyone know whats going on here?
You have not "added" your files to the repository, only to the staging index.
You need to git commit to get your changes from the staging index to the repository.
git status shows you the status of the working tree and staging index. git log shows you the status of the history - in other words, git log will show you what's been committed to the repository.
As an example, see this git status output:
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: Game.py
#
In this case, we can see that the changes to be committed involve Game.py. Note that these changes haven't yet been added to the repository - they're just staged, ready to be committed, as the git status says.
The next step is to commit these changes we've prepared in the staging index and add them to the repository. git commit is the command to do this.
This answer, as well as the linked Pro Git book, have some excellent reading which will help you understand the setup and steps in committing to a git repository.
I cannot see them in my actual repository.
What do you mean by "actual" repository? I am presuming you mean you can't see a local commit, but there may be some confusion about the repositories you're using.
You're using two repositories, one local and one remote. The remote repository is, in your case, on GitHub. You do your work locally, then git push to remote.
First, local changes and commits
So the steps to get your code changes into the local repository are as follows:
Make changes in your working directory. This is most often writing some code.
Build a commit by staging changes. This is done using git add.
"Save" the commit you've built into the repository. This is done using git commit.
These steps take place **locally*. None of these steps have any affect on your GitHub repository.
Secondly, git push to the remote repository (in this case, your GitHub one).
To get your code from local to remote repositories, git push is used.
Check what remote repositories are known by your local repository: git remote -v.
If the GitHub repository is not shown, you'll need to add it: git remote add <NAME> <URL>.
Because you didn't git clone, the two repositories (local and remote) don't have any commits in common. That's ok; it just means git doesn't automatically know where to push your changes, so you'll have to specifiy: git push <NAME> master:master. That'll push your local master branch to the <NAME> master branch.