Update forked repo with remote repo

Auto merge

Add remote repository

# cd <forked-repo>
# git checkout 
# git remote add upstream <upstream-repo-git-link>
#git fetch upstream

Updating fork from remote repo

# git pull upstream <upstream-branch>

Example (This is what I did to sync from remote branch and push to forked repo)

# cd <forked-repo>
# git checkout
# git remote add upstream <upstream-repo-git-link>
# git fetch upstream
# git pull upstream master --rebase

As local repo changes are rebased, faced error while pushing changes to forked repo. Runt these commands to rebase changes for forked branch.

# git pull --rebase
# git push origin <forked-remote-branch>


Force Update

If normal merge doesn’t wok and you are ready to do force update of your forked repo branch with original repo branch:

#git remote add upstream <upstream-repo-git-link>
# git fetch upstream
# git checkout <upstream branch>
# git reset --hard upstream/<upstream-branch>  
# git push origin <forked-remote-branch> --force 


Git send email

My git send-email config:

git config sendemail.smtpuser 
git config sendemail.smtpserver smtp.googlemail.com
git config sendemail.smtpencryption tls
git config sendemail.smtpserverport 587
git config sendemail.suppresscc self
git send-email --to <to_list> --in-reply-to="<message_id_of_message1>" --thread *.patch

This will generate patch in below way:
– Message 1
.           – Patch 1
.                       – Patch 2

This is how I prepared cover page followed by two patches:

git format-patch -2 --subject-prefix="PATCH v2" --cover-letter --thread=shallow
  • Here –cover-later would create a cover page. We need to modify subject and content.
  • The –thread=shallow flag specifies that all patches will be In-Reply-To your cover letter. Hence all patches would be in reply to cover page by default.
  • –subject-prefix=”PATCH v2″ would use given prefix in patch file.

This is how I sent this patches:

git send-email –to <to_id> –cc <cc_id> <patches>

The patch follows below sequence

  • Cover Page
    • Patch 1
    • Patch 2

example patch

Git useful commands

  • Git reset hard remote branch to specific commit
    # git reset --hard <commit-id>
    # git push -f origin <branch_name>
  • Add prefix in patch subject
    # git format-patch --subject-prefix=PREFIX][PATCH
      This will generate a patch with subject: [PREFIX] [PATCH]
  • Get list of new added files between two commits
    # git diff --name-only --diff-filter=A <old-commit-id> <new-commit-id>
  • Get list of modified files between two commits
    # git diff --name-only --diff-filter=M <old-commit-id> <new-commit-id>