0

1. Briefly

I don't find, how I can quick add, commit and push changes to 2 GitHub repositories both, that I don't need add, commit and push change to 2 GitHub repositories separately each time.


2. Example workspace

Local workspace:

SashaSource
    .git
    SashaSourceSubfolder1
    SashaSourceSubfolder2
    SashaOutput.github.io
        .git
        index.html
        SashaAnother.html

I have 2 remote GitHub repositories:

  • SashaSource — for SashaSource local directory;
  • SashaOutput.github.io — for SashaOutput.github.io local directory, location of my GitHub Pages site.

I use Pelican static site generator. I make a changes in SashaSourceSubfolder1 or SashaSourceSubfolder2 folder → I make a build (use make, fabric tools or pelican content command) → I get output in SashaOutput.github.io folder. (I set Pelican, that SashaOutput.github.io/.git folder don't change, if I make a build).

Now I want to push my changes to SashaSource and SashaOutput.github.io remote repositories.


3. Actual behavior

I need to run

git add . && git commit -m "Example commit description" && git push

in SashaSource repository than I need to run same command to SashaOutput.github.io repository.


4. Expected behavior

I print in terminal any command → git push changes to SashaSource and SashaOutput.github.io remote repositories both with a same commit description, that user don't need to run same command 2 times each time.


5. Not helped

  1. I read about git submodules, but I don't find, how I can solve my problem.
  2. I find, how I can push changes to 2 remote repositories. I set git remotegit add . && git commit -m "Example commit description" → I get output:

    D:\SashaSource\>git push all
    To https://github.com/Kristinita/SashaOutput.github.io.git
     ! [rejected]        master -> master (fetch first)
    error: failed to push some refs to 'https://github.com/Kristinita/SashaOutput.github.io.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull …') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 770 bytes | 0 bytes/s, done.
    Total 4 (delta 3), reused 0 (delta 0)
    remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
    To https://github.com/Kristinita/SashaSource
       dc36727..3e5d63b  master -> master
    

    My changes push to 1 remote repository. I think, that I need add and commit changes to SashaOutput.github.io before push, but I don't find, how I can do it.

  3. I read another Stack Overflow questions about push to 2 or more repositories, but I don't find in it, how user can add and commit changes to 2 repositories both.

  4. I don't understand, how I can to write script for expected behavior in my Windows. Commit description — is a variable, how I can use it in script?


6. Do not offer

  1. I need separate repository for my output SashaOutput.github.io, because GitHub Pages don't support source for Pelican and needs to be output directory in root of repository. Please, do not offer use 1 remote GitHub repository for my site, not 2.
  2. Please, do not offer, that I need to use Jekyll.

7. Environment

Operating system and version:
Windows 10 Enterprise LTSB 64-bit EN
git:
version 2.12.0.windows.1

Community
  • 1
  • 1
Саша Черных
  • 2,561
  • 4
  • 25
  • 71
  • Write a script (or an alias) which automates this job – LeGEC Mar 23 '17 at 10:29
  • Do you really use the command line `-m "message"` argument ? or do you actually type your commit message in the editor opened by git ? – LeGEC Mar 23 '17 at 10:29
  • 1
    FYI I found the easiest thing was to use e.g. Travis to run a CI build on updates to the source repo and push just the output directory to the GHP repo. This means that the source repo doesn't have the generated files in and the GHP repo doesn't have the source files in. See e.g. https://github.com/textbook/textbook.github.io-source, my own Pelican site; I created a scaffold you can fork and build on: https://github.com/textbook/pelican_scaffold – jonrsharpe Mar 23 '17 at 10:31
  • @LeGEC: I use `-m "message"` argument in command line. Thanks. – Саша Черных Mar 23 '17 at 10:47
  • @jonrsharpe: thanks for the answer. You push your changes to source repository and don't need push changes to site repository? Did I understand correctly? // If I understand correct, It is good, but [**I have a problem with CSS and JavaScript for individual pages**](https://github.com/mortada/pelican_javascript/issues/3). [**I need to change my Makefile**](https://github.com/Kristinita/KristinitaPelican/blob/master/Makefile#L67-L69) use Windows tool. Travis CI don't support Windows, AppVeyor don't support UNIX scripts and I don't know Linux. Thanks. – Саша Черных Mar 23 '17 at 11:05
  • That's right, I push changes to my source repo, which triggers the build. The build runs pelican and pushes the output to the site repo. I assume you could do something similar with AppVeyor, I've never tried. You could start as @LeGEC suggested by scripting it locally, then use that to transition to CI. – jonrsharpe Mar 23 '17 at 11:29

1 Answers1

0

Solution for Windows users.


1. Expected behavior

Script in section 3 add, commit and push changes to remote source repository (SashaSource in question), then add, commit and push changes to remote output repository (SashaOutput.github.io in question). For commit message for both repositories will set variable (%SASHAMESSAGE% in answer).


2. Set commit message

Print in your preferred terminal:

SET SASHAMESSAGE=[Test] Sasha Princess of the Universe!
  • SASHAMESSAGE — variable for commit message;
  • [Test] Sasha Princess of the Universe! — example commit message.

3. Batch file

Create file with bat extension, for example, GitPush2Repositories.bat:

git add .
git commit -m "%SASHAMESSAGE%"
git push
cd SashaOutput.github.io
git add .
git commit -m "%SASHAMESSAGE%"
git push
  • SashaOutput.github.io — your output folder.

4. Run batch

Open terminal in your source folder (SashaSource in a question) → print in terminal:

"D:\SashaBatch\GitPush2Repositories.bat"
  • D:\SashaBatch\GitPush2Repositories.bat — path to your bat file.

You must get expected behavior.


5. Extra links

Саша Черных
  • 2,561
  • 4
  • 25
  • 71