Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create local git repository based on local repository based on github repository and keep it updated

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.

like image 892
Alvaro Avatar asked Dec 25 '16 13:12

Alvaro


People also ask

How do I create a local git repository and push to GitHub?

In the command line, navigate to the root directory of your project. Initialize the local directory as a Git repository. To create a repository for your project on GitHub, use the gh repo create subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository.


3 Answers

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.

like image 95
VonC Avatar answered Oct 16 '22 17:10

VonC


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

like image 21
elicohenator Avatar answered Oct 16 '22 18:10

elicohenator


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

cd [PROJECT]/wp-content/themes

Now clone _s to your project:

git clone [email protected]: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!

like image 20
Amit T. Avatar answered Oct 16 '22 18:10

Amit T.