Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4051826
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:14:36+00:00 2026-05-20T14:14:36+00:00

I want to start using GitHub Pages for my project’s website. This simply requires

  • 0

I want to start using GitHub Pages for my project’s website. This simply requires a branch (subtree) named gh-pages in the repo, and serves up its content. The problem is that part of the website (manual, changelog, download page…) is auto-generated by the build system, so I want to find the best way to commit these changes to the gh-pages branch while the main repo remains on master (or wherever).

To commit to the gh-pages branch, I could write a script that clones the repo into a temporary directory, makes the modifications, commits them, and then pushes them back to the main repo. But this sounds like an error-prone process, so I’m hoping there is an easier way.

A friend suggested that I might add the gh-pages branch as a submodule to the main repository. I ran a little experiment, but it doesn’t quite work:

$ git init main
Initialized empty Git repository in /tmp/main/.git/
$ cd main
$ touch main.txt
$ git add .
$ git commit -m'Initial commit in main branch.'
[master (root-commit) 1c52a4e] Initial commit in main branch.
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 main.txt
$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm .git/index
$ git clean -fdx
Removing main.txt
$ touch index.html
$ git add .
$ git commit -m'Initial commit in website branch.'
[gh-pages (root-commit) 94b10f2] Initial commit in website branch.
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html
$ git checkout master
Switched to branch 'master'
$ git submodule add -b gh-pages . gh-pages
repo URL: '.' must be absolute or begin with ./|../
$ git submodule add -b gh-pages ./ gh-pages
remote (origin) does not have a url defined in .git/config

I’m new to submodules; have done some reading, of course, but I don’t understand this behaviour. Why does it need an origin remote? Ideally, I want the submodule to always reference the repo that it resides in, so it should not reference origin or any other remotes. If somebody clones the repo and runs git submodule init ; git submodule update, it should ideally pull from the newly cloned repo.

Is it possible to add a repo as a submodule of itself? Is it desirable? Are there any pitfalls that I need to be aware of? Is there a better way to achieve what I want?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:14:36+00:00Added an answer on May 20, 2026 at 2:14 pm

    In this case, the behaviour seems to be that git is trying to set the origin of the original repository to be the origin of the submodule. This is confirmed by the git submodule man page, which says [my emphasis]:

    <repository> is the URL of the new submodule’s origin repository. This may be either an absolute URL, or (if it begins with ./ or ../), the location relative to the superproject’s origin repository.

    A workaround that seems fine for me is to do the following:

    # Define origin to be the absolute path to this repository - we'll remove
    # this later:
    $ cd /tmp/main/
    $ git remote add origin /tmp/main/
    
    # Now add the submodule:
    $ git submodule add -b gh-pages ./ gh-pages
    Initialized empty Git repository in /tmp/main/gh-pages/.git/
    Branch gh-pages set up to track remote branch gh-pages from origin.
    
    # Now .gitmodules looks sensible:
    $ cat .gitmodules 
    [submodule "gh-pages"]
        path = gh-pages
        url = ./
    
    # However, the origin for the submodule isn't what we want:
    $ cd gh-pages
    $ git remote -v
    origin  /tmp/main/ (fetch)
    origin  /tmp/main/ (push)
    
    # So remove it and add the right origin (just ".."):
    $ git remote rm origin
    $ git remote add origin ..
    
    # Change back to the main repository and commit:
    $ cd ..
    $ git commit -m "Added the gh-pages branch as a submodule of this repository"
    [master 6849d53] Added the gh-pages branch as a submodule of this repository
     2 files changed, 4 insertions(+), 0 deletions(-)
     create mode 100644 .gitmodules
     create mode 160000 gh-pages
    

    This seems to work OK – if I change into another directory and do:

    $ cd /var/tmp
    $ git clone --recursive /tmp/main/
    

    … the submodule is updated and initialized correctly. (Update: although as you point out in a comment below, origin in the submodule will be set to the URL you cloned from rather than ..)

    As for whether this is a good idea or not: I’ve worked on a project which used a similar setup in the past and which subsequently abandoned it. The reasons for this, however, were (a) that the alternative branches in the main repository were huge and bloated the repository even for people who didn’t need the submodule and (b) that it caused confusion for people who weren’t sure what was going on.

    For your use case, however, I think it’s a rather neat solution 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to start using Bing for a project which will include working out
I want to start development using qt-embedded on my embedded device project. Can you
We have a python project that we want to start testing using buildbot. Its
I want to start using mock objects on my c# project. After a quick
I have a project configured via Autoconf, and I want to start using C++11
I want to start using table relations in a new project. After some googling
I want to start using more libraries for my codeigniter project, but I am
I want to start using memcache with PHP (on Ubuntu 9.10). There are lots
Hey everyone, I want to start using Scheme and I have two questions. First,
Very simple question, but I want to start using a consistent naming convention for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.