How to Git push a 'commit by another user'

+1 vote
asked Mar 29, 2016 by mr-bordoloi

Problem: In a certain directory, Git push is restricted to very few users(User1). Other users(User2) cannot push their changes here.

Is there a way so that - the User2 commits the changes(git add + Git commit) in that dir, then he provides the commit number to User1 and the latter does the Git push?

Can it be done?

1 Answer

+2 votes
answered Nov 8 by eckes

Usually, User2 does the changes and commits them. Then, she provides these changes to User1 who pushes the changes upstream.

The changes can be provided via various mechanisms:

  • User2 could git format-patch them and send the patches to User1 via E-Mail
  • User2 could use git request-pull in order to format an E-Mail holding details for User1 where she could find the changes (additional bare repo, direct read access to the machine of User2, ...)
  • Domain specific mechanisms (i.e. Github Pull Requests, Gitlab Merge Requests, ...)

Your requirement is not uncommon: lots of open source projects work just like this: while everybody could contribute changes, it's up to certain (trustworthy) people to integrate these changes into the actual project repository.

I'll provide some examples for how to use git format-patch or git request-pull here

  1. Create patches for the last 3 commits you did:

    git format-patch -3

    This will create 3 patch files that you could send via E-Mail to somebody that is allowed to commit on the upstream repo

  2. Create patches for all commits of the branch my-new-feature since you branched off from master:

    git format-patch 

    This will take each commit you did in my-new-feature and create a patch from it. Again, send these patches to the maintainer.

  3. Publish your changes to the maintainer directly from your hard disk (Windows):

    • Share your working directory with the maintainer (give her read access), say as \\yourmachine\yourworkingcopy. From now on, the maintainer could read the contents of the shared folder
    • Open up your console and let the magic happen:

      git request-pull origin/master file:////yourmachine/yourworkingcopy my-new-feature

      This spits out a ready made E-Mail text to the console that you could take and send to your maintainer.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.