-1

My local repo is behind a couple of commits on a specific branch. I have a commit on my outdated local repo.

How do I update my local repo to reflect the remote repo, and then apply my commit that I have made?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    Just run `git pull`? You may need to run `git stash` and resolve conflicts. – Obsidian Age Sep 13 '18 at 22:32
  • https://stackoverflow.com/search?q=%5Bgit%5D+update+local+repository – phd Sep 14 '18 at 11:40
  • @phd the question you have linked shows `git pull` as the accepted answer. If you read the question, OP clearly states he wants to apply git commit on top of the remotes changes. It's definitely not a duplicate of the one you've mentioned. – Danilo Souza Morães Sep 14 '18 at 18:46
  • `git pull --rebase` reapplies new local commits on top of the remote commits. I don't see how it's not the answer. – phd Sep 14 '18 at 19:10
  • Where's the word rebase on the accepted answer of the link you provided? The answer you linked to shows how to merge and that's not what OP asked – Danilo Souza Morães Sep 15 '18 at 06:07

2 Answers2

1

You could try git stash to save your local changes then git pull. To get the latest. It should then prompt you to merge

Flightdoc5242
  • 199
  • 1
  • 2
  • 12
1

The git rebase --onto command was created for that very use case. First fetch your remote branch, checkout the local branch you want to apply the remote changes to and then rebase:

git fetch origin <remote branch>
git checkout localBranch
git rebase --onto origin/remoteBranch localBranch~1

Note that ~1 should be changed to the number of commits you have on your localBranch that you want to replay on top of the remoteBranch. Since you pointed out that you only have 1 commit on your localBranch, this should work.

Danilo Souza Morães
  • 1,481
  • 13
  • 18