Skip to content

Instantly share code, notes, and snippets.

@vaidd4
Last active August 27, 2024 12:48
Show Gist options
  • Select an option

  • Save vaidd4/fbb69e126da0d6f20e1d76dc5be13f92 to your computer and use it in GitHub Desktop.

Select an option

Save vaidd4/fbb69e126da0d6f20e1d76dc5be13f92 to your computer and use it in GitHub Desktop.

Revisions

  1. vaidd4 revised this gist Jun 26, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git-orphan-worktree.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,8 @@ Exemple for *Github Pages* with a specific branch providing the static files:
    - Get back to your main branch: `git checkout master`
    - Create the worktree in a `public` folder: `git worktree add -B gh-pages public origin/gh-pages`

    Now, all the files put in the `public` folder can simply be committed and pushed to the `gh-page` branch.
    Now, all the files put in the `public` folder can simply be committed and pushed to the `gh-pages` branch.
    Example: `cd public && git add --all && git commit -m "Published to gh-pages" && git push origin gh-pages`.
    The rest of your repo will stay in sync with your main branch.

    To be sure to not mess with your main branch you can add the folder containing the worktree in your `.gitignore` file.
  2. vaidd4 revised this gist Jun 26, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git-orphan-worktree.md
    Original file line number Diff line number Diff line change
    @@ -7,16 +7,16 @@ This command will create a branch with no parent (no commit history) on a repo.

    ## Managing working trees
    Manage folders linked to others branches of your repo.
    Do not confuse them with `submodules` which are links to **differents** repositories.
    Do not confuse them with `git submodules` which are links to **different** repositories.

    You can create a folder in wich a branch of you repository is checked out.
    You can create a folder in wich a branch of your repository is checked out.

    [`git worktree <command>`](https://git-scm.com/docs/git-worktree)

    ## Usages
    Exemple for *Github Pages* with a specific branch providing the static files:

    - Create the new orphan page: `git checkout --orphan gh-pages
    - Create a new orphan branch: `git checkout --orphan gh-pages`
    - Clean all (untracked) files: `git reset --hard` or `git rm -rf .`
    - Create first commit: `git commit --allow-empty -m "Initializing gh-pages branch"`
    - Push the new branch on your repo: `git push origin gh-pages`
  3. vaidd4 created this gist Jun 26, 2019.
    29 changes: 29 additions & 0 deletions git-orphan-worktree.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # Git orphan branches & working trees

    ## Creating an ophan branch
    This command will create a branch with no parent (no commit history) on a repo.

    [`git checkout --orphan <new-branch>`](https://git-scm.com/docs/git-checkout/#Documentation/git-checkout.txt---orphanltnewbranchgt)

    ## Managing working trees
    Manage folders linked to others branches of your repo.
    Do not confuse them with `submodules` which are links to **differents** repositories.

    You can create a folder in wich a branch of you repository is checked out.

    [`git worktree <command>`](https://git-scm.com/docs/git-worktree)

    ## Usages
    Exemple for *Github Pages* with a specific branch providing the static files:

    - Create the new orphan page: `git checkout --orphan gh-pages
    - Clean all (untracked) files: `git reset --hard` or `git rm -rf .`
    - Create first commit: `git commit --allow-empty -m "Initializing gh-pages branch"`
    - Push the new branch on your repo: `git push origin gh-pages`
    - Get back to your main branch: `git checkout master`
    - Create the worktree in a `public` folder: `git worktree add -B gh-pages public origin/gh-pages`

    Now, all the files put in the `public` folder can simply be committed and pushed to the `gh-page` branch.
    The rest of your repo will stay in sync with your main branch.

    To be sure to not mess with your main branch you can add the folder containing the worktree in your `.gitignore` file.