Jason K
Jason K

Reputation: 65

Recreating git pushes

I have a odd assignment and I'm not sure how to do this...

I need to look at a public repo and once a day take all the pushes that happened on that repo and re-push them via a single account to another repo. Kind of like a mirror but more of a re-committing all pushes

Upvotes: 0

Views: 52

Answers (2)

LifeLongStudent
LifeLongStudent

Reputation: 2468

You need to use reset and rebase to do this.

Assuming you have repo.url

git clone repo.url
git remote add neworigin newrepo.url

Now create branch on local copy

git checkout -b myworkbranch

1) First time commit by single account

At this moment master and myworkbranch are in sync

Now see the log of all changes done on repo.url and see the first commit , take your head there by using git reset --soft

After that add all the files like you do normal push

git add --all
git commit -m "My combined push"
git push neworigin myworkbranch:master

This will push all changes in single commit first time , note the commit id

2) Ongoing pull and changes push

git checkout master
git pull
git checkout myworkbranch
git rebase master
git log 

Now again you are ready to reset

git reset --soft To commit id you noted earlier

git add --all
git commit -m "My second combined commit"
git push neworigin myworkbranch:master

Keep on repeating

Not tested , but should work.

Upvotes: 2

kenorb
kenorb

Reputation: 166359

Assuming you've repository already cloned, add another remote to where you want to push, e.g.

git remote add mirror [email protected]:foo/bar.git

Then pull from origin (upstream) and push to another repository, e.g.

git pull origin master
git push mirror master

Make sure you have appropriate access to push to both repositories.

To check your current configured remotes, run: git remote -v.

To do this task once a day, create a script and add its execution to crontab or if you're using Linux then copy the script to /etc/cron.daily folder (if it's supported by your system).

Upvotes: 2

Related Questions