Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force git push for one file

Tags:

git

My repo has two files: G.txt and I.txt. G.txt is edited by other users, while I am the only user who modifies I.txt, and I do not modify G.txt. My usual workflow is as follows:

  1. git pull
  2. Edit I.txt
  3. git add I.txt; git commit -m "message"; git push

I usually run into trouble because between steps 1 & 3, someone else has edited G.txt, so my push fails. People are quite often pushing to G.txt, so it is very difficult to fit my pull and push in before someone else does an edit. Is there a way to force the push to accept my change to I.txt, but not to overwrite the repo's G.txt since others have changed it since my last pull?

like image 521
James Avatar asked Feb 28 '26 01:02

James


1 Answers

You can git pull --rebase: that will replay your local (with l.txt modification) commit on top of any other commit done on the remote side.

Then push again. No need for forcing the push in that case.

like image 84
VonC Avatar answered Mar 01 '26 17:03

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!