Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push single outgoing commit in TFS Git

Tags:

git

tfs

I have multiple unsynced, outgoing commits on my branch. I want to push one of them to my online repo, while I want to wait with pushing others (they're part of a larger process).

If you look at the screenshot below, how can I push only the first commit?

enter image description here

like image 769
Benjamin Avatar asked Mar 16 '26 13:03

Benjamin


1 Answers

There is no simple way of doing that. I don't know how to do this from Visual Studio, but here is below the way how this can be done from command line using git utility.

Let's assume that your main branch has name "master" and you are currently checked in to it.

  1. Create a temp branch from your master:

    git checkout master
    git branch temp
    
  2. Reset master branch to origin/master so that to return it to the initial state when it didn't have your commits yet:

    git reset --hard origin/master
    
  3. Get all commits from remote master to synchronize your local and remote "master" branches. This step is necessary if there are commits you don't have yet in your local copy e.g. smbd else pushed while you were working locally. Anyway it worth to do it just to make sure:

    git pull origin master
    
  4. Now you can cherry-pick your last commit to master:

    git cherry-pick <hash_of_last_commit_in_temp_branch>
    
  5. Now you can push this commit to remote:

    git push origin master
    
  6. Now merge the rest of your commits from temp branch back to master branch:

    git merge temp
    
  7. And finally remove temp branch:

    get branch -d temp
    

That's it.

like image 63
Alexey Andrushkevich Avatar answered Mar 18 '26 01:03

Alexey Andrushkevich



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!