noober
noober

Reputation: 1505

git - how to replace a local git branch with the online branch

Git newbie here. What is the best practice and clean way of replacing my local version of my branch with the branch that I uploaded previously, but made modifications to files using the online editor?

I did the following. I created a branch and pushed up changes. Instead of modifying my files locally, I used the online editor to make changes to those same files. Now roll forward a week or 2 later. I forget to pull any other changes.

Now my local repo seems to have issues after doing a git pull.

What i would like to do is simply pull down the online branch and somehow reset my local with that version. How can I do that for my local branch? Was it bad practice to use the online editor to make changes? vs modifying the files locally and then pushing them? Thanks.

Upvotes: 0

Views: 66

Answers (1)

Ben Straub
Ben Straub

Reputation: 5776

What you've got here is the same situation as if another person on your team pushed changes to the server while you were making changes on your local machine, and the solutions are the same. Start by updating your local tracking branch by running git fetch. Then:

  • If you want to keep just the remote changes, do git reset --hard origin/thebranch.
  • If you want to keep both sets of changes, do get merge origin/thebranch (or git pull).
  • If you want to keep both sets of changes, but without a merge commit, do git rebase origin/thebranch (or git pull --rebase).

As for whether this is a best practice or not, it really depends on your team. Some teams like the tests to always be passing, and there's no way to run the tests before committing when you're editing on a web page.

Upvotes: 1

Related Questions