0

I have a project I am working on on both my laptop and my home PC, I pushed something from the laptop earlier to my git repo that was a minor change. Now I have done a lot of changes from my home PC and I am trying to push those onto the repo.

However it says I have to pull first because there are changes in the repo that I dont have locally.

The thing is those files dont have the major changes I have done on my home PC and I dont want to lose my local content just cause I pulled down the earlier versions from the repo.

How can I force my files onto my repo without pulling?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Flux
  • 410
  • 1
  • 5
  • 19
  • Why haven't you been pulling the changes more frequently? You know that pulling doesn't just remove your changes (you'll have to [merge or rebase](http://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge))? – jonrsharpe Jan 24 '16 at 08:56
  • I am not very good at git. No I dont have other collaborators, just myself with two pcs. The problem is I didnt pull before I started doing changes cause I aint that used to git. – Flux Jan 24 '16 at 08:58
  • You don't loose your local content, you merge the changes of others with your own changes. You need to do this before you pull, or you must push to a different branch, but eventually you will have to merge those changes. – GolezTrol Jan 24 '16 at 08:59
  • Git makes it very difficult to lose anything. I suggest you read through a git tutorial to get the basics. – jonrsharpe Jan 24 '16 at 09:03

3 Answers3

2

You can force push,

git push origin master --force

Or use the short flag,

git push origin master -f
Msp
  • 2,493
  • 2
  • 20
  • 34
1
git pull --rebase origin branchName

This will first pull the changes onto your local repo (your PC) and then apply your local changes on top of it.This way you don't loose the changes you have made locally. After this you can just do a

git push origin branchName

This will then update your remote repo.

adarshdec23
  • 231
  • 2
  • 9
1

You don't loose your local content when you pull; you merge the changes of others (in this case of yourself from the other PC) with your own changes.

You could push to a different branch and drop the branch that has the other changes.

I think the best way is to just fetch the changes (pull without merge), and sort out the differences yourself. If you have a graphical git client like SourceTree and a 3 way merge tool like KDiff3, that will certainly help a lot.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210