0

So,

I am current working on a fullstack project. The folder structure of the same looks like following.

/client
  /.next
  /app
  /components
  .
  .
  .
/server
  .
  .
  server.js
  . 
  .

I have initialized git in the top level folder from where I push to a remote github repo. All fine till here.

but, now I have this final build .next folder ready and I want to push only the contents of this folder to a branch in the same repo. I cant figure out around this how to.

I have tried the following git codes

>git checkout gh-pages
>git add /client/.next
>git commit -m "Build"
>git push -u origin gh-pages

and, instead of only pushing the contents of the .next folder it pushed the whole root directory

Karthik
  • 1
  • 4
  • 1
    And what happened when you executed those statements? – Joachim Sauer Jul 27 '23 at 15:05
  • @JoachimSauer Instead of just pushing the contents of the .next folder it pushed the whole root directory. – Karthik Jul 27 '23 at 15:07
  • 1
    _"make subfolder as a branch"_ doesn't make sense in git. A branch is a pointer to a commit, which itself is a snapshot of the _whole repo_. – evolutionxbox Jul 27 '23 at 15:08
  • Ah, what you want is probably a new branch that's *entirely unrelated* to your main branch. That's somewhat unusual, but is usually done for things like `gh-pages`. Check out [this question](https://stackoverflow.com/questions/34100048/create-empty-branch-on-github). – Joachim Sauer Jul 27 '23 at 15:09
  • @evolutionxbox then how what would be the roundabout solution for the same problem without branches. I read worktrees could solve this, but couldn't quite understand. – Karthik Jul 27 '23 at 15:10
  • Does this answer your question? [Create empty branch on GitHub](https://stackoverflow.com/questions/34100048/create-empty-branch-on-github) – Joachim Sauer Jul 27 '23 at 15:10
  • @JoachimSauer I think --orphan would work. but what if I had to change branches in my workflow and then when I change back to this branch. would it still push only the .next folder? – Karthik Jul 27 '23 at 15:14
  • Just switching between branches doesn't magically change either branch. The two branches will behave like any other two normal branches afterwards, except they will not have a shared common ancestor (which means for example that merge will decline to merge them by default). – Joachim Sauer Jul 27 '23 at 15:16
  • @JoachimSauer Ohh! Does that mean creating a new branch using "git checkout" duplicates the current branch? – Karthik Jul 27 '23 at 15:20
  • "duplicates" is the wrong word, but yes it does what you think. By default new branches are based on the current commit, so they "branch" the history at that point. Orphan branches are, as I said, a rather rare beast, as a git repository usually contains one thing/project and its history through time. – Joachim Sauer Jul 27 '23 at 16:07
  • *"I have initialized git in the top level folder"* - this means that repository will track content of this top level folder. If you want to tack content of some other folder then you'll need to create a separate repository. – user7860670 Jul 28 '23 at 07:36

0 Answers0