A simple script to sync a forked repository with the source repository


The mechanism is simple like this:

1. Pull/Clone your own repository(which was forked from another repository) to a local PC.
2. Add remote source repository to a tag of the local copy.
3. Do local merge for the two repositories.
4. Resolve the conflications if exists.
5. Commit the local copy to your repository.
6. Done and do some check.

#Sync the forked repository with the original source

#1. First clone the repository of your own.
#Skip this step if you already have a local copy of your own fork repository
git clone https://github.com/jackyhwei/nginx-rtmp-module
cd nginx-rtmp-module

#2. Add remote repository

#Add a tag for your repository and point to the origin source repository
git remote add jackyhwei https://github.com/arut/nginx-rtmp-module

#3. Fetch the newly added tag source
git fetch jackyhwei

#4. Merge the newly fetched source to master
git merge jackyhwei/master

#Manually resolve the conflications if there exists
git commit -m "merged by jackyhwei"

#5. Push the codes to your repository. BTW: git push requires you input your username and password.
git push -u origin master

#6. Check local info
git remote -v  
git branch -a

If you’v made some modification for your own repository, there will be an error like below when you do the push:

Permission denied(publickey).
fetal: The remote end hung up unexpectedly.

It’s because you didn’t add a public key for your repository, use following script to add it:

cd ..
mv .ssh ssh_bak
ssh-keygen #this command will generate a public/private rsa key pair for you.
cd .ssh
ls #there would be two files: id_rsa and id_rsa.pub
vi id_rsa.pub

Copy the contents in id_rsa.pub to your clipboard, and go to the repository administration web page, select the Deploy Keys menu, and Add the deploy key(which is in your clipboard) to it.

Try push again.

Leave a comment

Your email address will not be published. Required fields are marked *