0

Unfortunately I wasn't able to find the answer to my specific problem through research, so I am looking for some help. The answer may be out there, but I don't have a good enough understanding to determine whether it will help me in my current situation. I am relatively new to git, and I need to get the latest changes from the repository which I forked from.

Here is what I have done prior:

  1. I forked the repository to create a copy of my own.
  2. I cloned my copy to my machine using git clone.
  3. From my forked copy, I created a new branch to work off of, and committed some changes.
  4. I created a merge request to merge my branch with the main repo, but it has not been merged yet.

Some changes have been made to the main repo, and I have been asked to continue working on the branch which I requested to be merged. I now need to pull the code from the master of the main repo, and bring it into my branch so I can continue working with a project that is up to date.

I was told to do a 'git pull origin master', however, I notice that the origin (after doing git remote -v) is my copy of the repo. Now to my question: Would the 'git pull origin master' be the correct thing to do in order to get the most recent code from the main repo into my branch that is checked out (and not merged yet)?

Just a side note: I am currently in training, so this may not be how the process usually goes, but I just want to make sure I am doing things correctly. If you need any more information to answer the question, please let me know. Thanks.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
tb517
  • 317
  • 4
  • 17
  • Possible duplicate of [How do I update a GitHub forked repository?](https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository) – jmargolisvt Jan 17 '18 at 20:12
  • In my case, the pull request has not been accepted, so the changes in my branch have not yet been merged to master. Does this duplicate still apply? – tb517 Jan 17 '18 at 20:17
  • Maybe you should switch to another branch until your PR is done. Or do you intend to add more changes to the PR? – juanchopanza Jan 17 '18 at 20:33
  • Yes it does. This ^^ is also good advice. When I was learning git I made defensive copies of my branches I didn't want to mess up just in case I needed to blow everything away and start over. `git checkout -b feature-branch-BACKUP` then switch back over to your feature branch and have at it. – jmargolisvt Jan 17 '18 at 20:40

1 Answers1

0

Sounds like you want to do git pull remote_repo master where remote_repo is the name that appears when you do git remote -v for the remote repository.

If the remote repository doesn't appear when doing git remote -v then you should add it git remote add upstream upstream_url you can choose whatever name, I like upstream.

jmoney
  • 443
  • 2
  • 10
  • Just so I am clear, when I do a 'git remote -v' I get the following: origin (fetch) origin (push) If I do a 'git pull origin master', will this pull from my copy? I am wanting to pull the latest changes from the repo which I made a copy from. These changes need to be applied to my copy and the branch I created within my copy. – tb517 Jan 17 '18 at 20:18
  • If you want to pull from the original repo, the one you copied. Then you would need to add it as a remote locally, as I said, and then pull from it. If you pull from origin, where origin is your copy, then that won't pull from the original repo. – jmoney Jan 17 '18 at 20:26