0

The problem I face is the following. I created a Branch. I made a couple of commits and then made a Pull Request.

After the code review, the reviewer made 2 comments, and rebased with the UI(Gitlab), the remote of the Branch. Now my local changes do not have the latest commits. But before I address the comments he made, I need to bring the changes to local.

What I did, and I am really not sure, it is correct, is git fetch and the pulled the origin of my branch, which theoretically should be the remote.

git fetch
git pull origin myBranch

Is there a better way to do that. I am struggling with this kind of situation and not sure if my approach is correct. Thanks!!

1 Answers1

0
git fetch //Fetch all remote branches.

git checkout yourBranchName //Switch branches or restore working tree files

git pull origin yourBranchName //Fetch from and integrate with another repository or a local branch

git rebase mainBranchName yourBranchName //Reapply commits on top of another base tip

git push --force origin yourBranchName // Update remote refs along with associated objects forcefully

For more details please check

Parth Raval
  • 4,097
  • 3
  • 23
  • 36
  • 1
    The `--all` flag to `git fetch` means fetch from all *remotes*. It automatically fetches all branches (modulo any settings from `--single-branch`, which `--all` does not override). Supplying `--all` to `git fetch` is usually useless-but-harmless, since most Git repositories have only one remote. – torek Oct 16 '19 at 08:38
  • 1
    Having run `git fetch`, it's not necessary to use `git pull`: `git pull` just means *run `git fetch`, then run a second command, typically `git merge`*. (You can select `git rebase` as the second command instead.) So, either use `git fetch` and then the appropriate second command, *or* use `git pull`. An extra fetch is generally harmless, but as with `--all`, it's also not generally useful. – torek Oct 16 '19 at 08:40
  • 1
    Some people strongly prefer using `git pull`; I strongly prefer avoiding it, in favor of doing the two separate commands. That's more a style issue, though. – torek Oct 16 '19 at 08:40
  • @torek, Thank you for your suggestions I will update my answer according to your suggestions. that's better :-) – Parth Raval Oct 16 '19 at 08:42