10

I have some basic git knowledge but I'm not sure how to accomplish this.

I am trying to clone (?) github WordPress starter theme underscores. The idea is to create a basic framework based (with some modifications) on that repository. Then create other themes with that framework as the base.

So it should look something like:

  1. copy github underscores repository to local

  2. create a local repository my_framework from the underscores one, modifying certain parts of those files always (such as the name) and adding some other files

  3. create new local repositories my_theme1, my_theme2 based on my_framework

The goal is to keep everything updated with any underscores update, while changing and modifying the framework and the themes. Once the content from github is pulled it should keep (or inform) of any updates, but I don't need any change I make locally to go back in the path.

I am not sure which path to follow, and would appreciate any help or pointer.

Alvaro
  • 9,247
  • 8
  • 49
  • 76

5 Answers5

10

The goal is to keep everything updated with any underscores update, while changing and modifying the framework and the themes

That is called the triangular workflow:

https://i.stack.imgur.com/Lx7do.png

  • fork (see "Fork a Repo") the repo automattic/_s
  • clone that fork locally,

    git clone /url/my/fork myfork
    
  • add as remote upstream the original repo

    cd myfork
    git remote add upstream https://github.com/automattic/_s
    

From there, with git 2.9 or more, configure:

git config --global pull.rebase true
git config --global rebase.autoStash true

Finally, each time you want to update your branches (where you modify your own version of the original repo), do a

git checkout mybranch
git fetch upstream
git rebase upstream/master

Then you can merge that updated branch (after testing it) to your other repos my_theme1, my_theme2, cloned from myfork.

cd my_theme1
git fetch
git merge origin/mybranch

If you want to work locally only, you can skip the fork step and clone directly the original repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Why is it necessary the fork in the first step? – Alvaro Dec 31 '16 at 12:15
  • Because you don't have the right to push to the original repository – VonC Dec 31 '16 at 12:16
  • But couldn't I push to the local clone instead? – Alvaro Dec 31 '16 at 12:20
  • You work (commit) in your local clone, you push to your remote fork. – VonC Dec 31 '16 at 12:24
  • Thanks @VonC. I ask because I wanted to know if it was possible to keep everything local, so there is no way to make the fork local (probably not a fork but maybe a clone?), right? – Alvaro Jan 02 '17 at 22:33
  • @Alvaro "fork local (probably not a fork but maybe a clone?)": exactly: if the fork is not done on GitHub... it becomes a simple clone. – VonC Jan 02 '17 at 22:34
  • Sorry, maybe I am miss understanding the first step. You are proposing to fork the original repo and then clone the fork, then work on the clone. So there is no way to clone the original repo (without previously forking) right? Because if Im understanding it correctly the upstream will send local changes to that (online) fork. – Alvaro Jan 02 '17 at 22:39
  • @Alvaro yes: if you want to push back, you need to push back to a repo you own (hence the fork step, which creates a repo that you own) – VonC Jan 02 '17 at 22:40
  • And there is no way (in the process you propose) to not push it to the online fork, so everything stays local? – Alvaro Jan 02 '17 at 22:41
  • @Alvaro if everything stay local, you don't need to fork step: you can directly clone the original repo and never push back... but that is not really the Git way;) If anything bad happens to your local storage, the all "distributed" aspect of Git won't save your work. – VonC Jan 02 '17 at 22:43
  • Thanks @VonC, I could express what I meant finally :) I understand. If still I want to do so, and I understood it correctly, I just skip that first step and clone from the original repo directly. – Alvaro Jan 02 '17 at 22:45
  • @Alvaro "I just skip that first step and clone from the original repo directly." Exactly. I have edited the answer to include just that. – VonC Jan 02 '17 at 22:47
  • Since OP claims only basic knowledge of git, I would be cautious about globally setting pull.rebase without a thorough understanding of what it does. It may often (or even usually) be better than merging, but changing default behaviors can be confusing for new users. Otherwise +1, nice clear explanation. – eaj Jan 03 '17 at 16:47
2

you should learn about child themes. the concept of it is having a main theme - which gets updated - and a child theme that'll you'll modify, add content, create different templates & styles... everything to your needs.

I'd recommend taking some minutes to read this throughtfully: https://codex.wordpress.org/Child_Themes

elicohenator
  • 747
  • 6
  • 17
  • Thanks @elicohenator. I know about Child themes. The thing is right now every time I build a theme I download the underscores source, replace names, delete extra stuff, add a bunch of php, Grunt, etc. manually and build from "scratch" (when I could reuse most of the source code and files). So I thought it would be great to keep it organised, automated and under a version control. – Alvaro Dec 25 '16 at 22:15
  • in this case you can create your own repo of underscores' modifications, than clone it to your current project. you can include there SASS files, page templates and other stuff you need. (i'm doing it with a Foundation starter theme called FoundationPress) – elicohenator Dec 26 '16 at 10:06
1

Assuming you using a terminal, cd to the themes directory:

cd [PROJECT]/wp-content/themes

Now clone _s to your project:

git clone git@github.com:Automattic/_s.git [THENE-NAME]

After the clone ends you can start working with your new theme. cd to theme directory:

cd [THENE-NAME]

and create another remote for your repo.

git remote add [NEW-RENOTE-NAME] [NEW-RENOTE-URL]

From now on, you can push change into your private remote:

git push [NEW-RENOTE-NAME] master

and if you want to get updates from _s repo you can just:

git pull origin master

Good Luck!

Amit T.
  • 83
  • 2
  • 12
0

you could do something like
git clone https://github.com/Automattic/_s.git
create directory my_framework with mkdir my_framework(if on windows)
cd my_framework
git init
git remote add <_s> <PATH to your local underscore>
git pull(to get latest version of underscore)
again:
mkdir my_theme1
cd my_theme1
git init
git remote add <my_framework> <PATH to your local my_framework>
git pull

Hope this is what you are looking for!

pavitran
  • 814
  • 1
  • 10
  • 25
0

What you want to do is called nested git repo. GitHub does not allow nested repositories. You can use GitSubmodule or subtree. It is done for when projects become bigger.

One copy of underscores will remain as "control". Second copy of underscores will remain is starting of my_framework. Third copy is copied and modification of my_framework.

You can :

  1. Update underscores repo aka WordPress starter theme underscore master separately
  2. Change in your framework separately
  3. Send pull request for wherever you want to contribute

my_theme1, my_theme2 are not versions but separate softwares. my_theme1 as example can have nth versions. Here are sample steps :

cd ~ 
mkdir parentrepo 
cd parentrepo/ 
git init . 
mkdir child1 
mkdir child2 
cd child1/ 
git init . 
echo "FirstChildRepo content" > child1repofile.txt 
git add . 
git commit -a -m "Adding FirstChildRepo content" 
cd ../child2/ 
echo "SecondChildRepo content" > child2file.txt 
cd .. 
echo "parentrepofile" > parentFile.txt 
git add . 
git commit -a -m "Adding Parent Repo content" 
# verify whether working independently 
cd ~/parentrepo/ 
git log 
cd ~/parentrepo/Child1Repo/ 
git log 
# try cloning parent, verify the contents
cd ~ 
git clone parentrepo/ 
cd parentrepo/ 
ls -a 
./  ../  .git/  child1/  child2/  parentfile.txt 
cd child1/ 
ls -a 
./  ../ 

Work after this step to clone, update in the way whatever like others written.

You can "auto update" too. Add files named post-checkout & post-merge to .git/hooks directory of the needed repositories and add this into each of them:

#!/bin/sh
git submodule update --init --recursive
Community
  • 1
  • 1
Abhishek Ghosh
  • 1,161
  • 9
  • 19