Search code examples
gitgithubgithub-pagespelican

Add, commit and push to 2 remote GitHub repositories


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


Solution

  • 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