User Tools

Site Tools


docu:csheet:sysadm:script:git:merge_upstream

Merge the upstream of your fork automatically


We will use the https://git.nogafam.es/nogafam/instante-social repository for the example (as a fork of Mastodon):

# clone your repo (if you didn't yet)
git clone https://git.nogafam.es/nogafam/instante-social.git
cd instante-social
 
# on the project root path, add a new remote called "upstream"
#  (a standard way to call it, but you can call it whatever)
git remote add upstream https://github.com/mastodon/mastodon.git
 
# this previous steps, will only be done ONCE. 
#  If you already have remotes configured, skip previous steps
 
# get all upstream data and pull "main" branch
#  (mastodon's main branch is called "main", not "master")
git fetch upstream
git pull upstream main
 
# now, if there is unexpected changes (conflicts), you will have to merge
#  this snippets can help you automate the process if you want HEAD of all conflicts
#  IMPORTANT: when not, solve conflicts manually, and use "git add". Use at your own risk.
#
# reset changes on conflicted files
git status | grep -i 'both modified:' | awk '{print $NF}' | xargs git reset
# restore those files to put your changes first
git status | grep -A 10000 'git restore' | tail -n+2 | awk '{print $NF}' | xargs git restore
 
# now commit your changes to do the merge and push changes
#  (we obviate the fact that the main remote is called "origin"
#   and also obviate the main branch is called the same: "main")
git commit
git push origin main
docu/csheet/sysadm/script/git/merge_upstream.txt · Last modified: 2021/10/20 07:19 by admin