ryudice
ryudice

Reputation: 37456

Push changes to remote repo without commit

Is it possible to push changes to a remote repository without commiting to the master branch? I use the remote repo just for deploying.

Upvotes: 47

Views: 95246

Answers (8)

neimad
neimad

Reputation: 594

My workaround for this is to stash all the current changes. Then get the SHA for the stash, and then push that, and then finally apply the stash so I can keep working from where I left off, without committing work-in-progress code.

I work on a system where I have to git-push to a remote dev server to test any changes to front-end code, so the stash/push SHA/apply-stash workaround has become part of my development workflow.

Upvotes: 0

AKACHI_4
AKACHI_4

Reputation: 1

I get that when we push changes directly without generating a commit so changes don't reflect in the corresponding branch, you must generate a commit either it will empty or not before pushing into the origin.

Upvotes: 0

Sophana
Sophana

Reputation: 1

One solution I use is to use git diff to get a patch file and then apply the patch to remote repo with patch.

I have no automatic tested script to propose, but the idea is to reset remote repo to the same state as local repo using git reset --hard

Then git diff > patch.txt, transfer patch file, and apply with patch -p0 < patch.txt.

This should work for simple modifications, but won't work with deleted/added files and other changes.

Upvotes: 0

cbaigorri
cbaigorri

Reputation: 2725

You can amend your last commit with the --no-edit option then force push the branch.

git commit --amend --no-edit
git push origin <remote name> -f

Upvotes: 11

fresskoma
fresskoma

Reputation: 25791

No, there is no way to do that, as it would completely oppose the whole "git strategy", I guess. I don't know about your deployment system, but I guess a good way to do what you are trying to is to work on different branches (that is, on for development and one which gets deployed when pushed to), and merging the changes you want to be deployed from your development-branch into your live branch.

Upvotes: 15

Andrew Homeyer
Andrew Homeyer

Reputation: 8108

You can create an empty commit and push that: git commit --allow-empty

Upvotes: 110

sabalaba
sabalaba

Reputation: 1294

If you want to push a specific commit:

git push <remotename> <commit SHA>:<remotebranchname>

Upvotes: 1

Ryan Bigg
Ryan Bigg

Reputation: 107728

No, you must make a commit before you can push. What is being pushed is the commit (or commits).

Upvotes: 6

Related Questions