ThomasReggi
ThomasReggi

Reputation: 59345

Pushing without committing

I have a git repo and I just pushed it to a server. Then I setup a post-receive hook on the server. I want to check it works. I have to commit again just to see if it works? I would really like to just force a push while I'm trying to get this set up rather than keep making commits that have no real value. Its not working, and I just don't get it.

$ git push --force origin master
Everything up-to-date

Upvotes: 7

Views: 11998

Answers (2)

tmr232
tmr232

Reputation: 1201

There's a little dirty trick you can use:

git stash save && git push --force origin "stash@{0}:master" && git stash pop

This does 3 things:

  1. Stash current uncommitted changes. Stashing creates a new commit, but on a separate ref. It will not dirty your history. Additionally, it clears the working directory from the changes. See step 3.
  2. Push the stashed code
  3. Pop the stash - clearing the stash and placing all the files back in your working directory.

This will effectively push all files to the remote without creating a local commit.

Upvotes: 3

ThiefMaster
ThiefMaster

Reputation: 318468

You need to push an older commit to achieve this. For example, you could push the commit right before the current HEAD using this comment:

git push --force origin HEAD^:master 

After this you can push the HEAD commit again:

git push origin master

However, instead of pushing all the time consider calling the hook manually. That's usually easier - but don't forget to test with an actual push when you think everything works just to be sure.

Upvotes: 7

Related Questions