Extremely Serious

Category: GitHub

Pushing files with More than 1MB in Size via HTTP in Git

For some reason, you have files with more than 1MB in total size to push to git respository by HTTP. You might be surprised that you cannot do it. This is because by default, git only posts to remote server via HTTP protocol with a maximum of 1MB. To remedy this, increase the http.postBuffer to 500MB (i.e. if you have to send files with 500MB total size) on client side like the following:

git config --global http.postBuffer 524288000

Reference

https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-config.html

Downloading a GitHub Pull Request

  1. Open an open pull request on GitHub which normally has the following format:
  2. Open a terminal for running a git command (e.g. bash, cmd, powershell, etc...).
  3. Navigate to the location where your git forked repository was cloned.
  4. Download a copy of a pull request using the following command:
    git fetch upstream pull/<ID>/head:<NEW BRANCH>

    Where the variables can be describe as the following:

    <ID> This is the associated code attached to the pull request. Normally has the following format #<ID> (e.g. #123) or see the format from step 1.
    <NEW BRANCH> This is the unique desired branch name on your fork.
  5. Switch to the new branch and do what you want (e.g. code review, testing) using the following command:
    git checkout <NEW BRANCH>

Resetting GitHub Forked Master with Upstream Master Branch

If your GitHub forked master branch is ahead from the upstream's master branch and you wanted to make it even (i.e. also lose some work). The following procedure might help you.

Note: If you have your default branch protected perform steps 1, 2, 3, 7, 8 and 9.  Otherwise just do steps 4, 5 and 6.

  1. Open a terminal (i.e. powershell, cmd, bash) and checkout the master of the upstream to a temporary branch (i.e. this could be anything) using the following syntax:
    git checkout -b <temporary-branch> upstream/master

    Example

    git checkout -b temp-branch upstream/master

    Where <temporary-branch> is temp-branch.

  2. Push the temporary-branch to your origin using the following syntax:
    git push origin <temporary-branch>

    Example

    git push origin temp-branch

    Using the <temporary-branch> from the example in step 1.

  3. On your browser, access your forked GitHub project and update the default branch to your temporary-branch.
  4. On your terminal (i.e. powershell, cmd, bash), switch to your master branch using the following command:
    git checkout master
  5. Reset the master based on the upstream's master branch using the following command:
    git reset --hard upstream/master
  6. Push the update to your master using the following command:
    git push origin master --force

    Note: If you didn't do step 3 this and the branch is proctected command will fail.

  7. On your browser, access your forked GitHub project and update the default branch to master.
  8. Going back to your terminal, delete the local temporary-branch using the following syntax:
    git branch -D <temporary-branch>

    Example

    git branch -D temp-branch

    Using the <temporary-branch> from the example in step 1.

  9. Delete the remote temporary-branch on your origin using the following syntax:
    git push origin --delete <temporary-branch>

    Example

    git push origin --delete temp-branch

    Using the <temporary-branch> from the example in step 1.