Harrix Harrix - 4 months ago 9
Git Question

How do I make a commit is not in the maser branch with git-worktree

I have a repository with name "Name" for example. And in the repository has two branches:


  • master

  • gh-pages



If I have made changes to the folder "Name", the commands I get the commit:

$ git worktree add ../Name-gh-pages gh-pages


With this command, I get two directories:


  • "Name" with files from "master" branch

  • "Name-gh-pages" with files from "gh-pages" branch



If I have made changes to the folder "Name", the commands I get the commit:

$ git add .
$ git commit -m "test"


How do I commit if I make changes to a folder "Name-gh-pages"? Command "git add ." sees the changes only in the folder "Name". Command "git checkout gh-pages" is not working in this case.

Update. jibe suggested solution.

$ git worktree add ../Name-gh-pages gh-pages


We now have two working directory.

$ git add .
$ git commit -m "test"
$ git push


We've committed to the "master" branch.

$ cd ..
$ cd Name-gh-pages
$ git add .
$ git commit -m "test gh-pages"
$ git push


We've committed to the "gh-pages" branch.

Answer

As you indicated it, $ git worktree add ../Name-gh-pages gh-pages your modification on gh-pages are tracked on Name-gh-pages folder. You should simply go in Name-gh-pages and then you will be to make modification, commit and push. But you cannot have 2 linked repositories tracking the same branch that is why you cannot checkout gh-pages from Name folder.

Comments