0

I've been given several tasks, and each task should be pushed it its own branches. For example, task_1 files into task_1 branch. I've created branches from task_1 to task_8 for each task.
However, before working on a specific task, let's say task_3, I created a new branch for task_3 by git branch -M task_3. Then, I created a folder named task_3 and kept all files related to the task there. Having finished the task, I did: git add task_3 and git commit -m "task 3 finished" and git push origin task_3.
The funny thing is all the previous commits (task_1 and task_2) were pushed to task_3 branch. For example, in task_8 branch, all the previous commits were also pushed to task_8 however I added only task_8 folder to the staging area then made a commit and push.

Is there any way to ignore previous branches and commits when pushing files to each lastly created branch?

The repo is here.

Also, I am asked to create a pull request on each branch and files should be added to the main branch before merging. How am I supposed to do that?

I appreciate your help.

jkalandarov
  • 300
  • 2
  • 10
  • Why are you using the `-M` flag with `git branch`? I think that's the cause of your problems. – Dai Jan 22 '22 at 08:18
  • "Then, I created a folder named task_3 and kept all files related to the task there" - that's not how you're meant to use branches in git. Git is nothing like SVN or TFS: branches don't exist as a subdirectory within the repo's filesystem, instead a git branch is an entirely separate timeline: like a parallel-universe. – Dai Jan 22 '22 at 08:20
  • "Is there any way to ignore previous branches and commits when pushing files to each lastly created branch?" - because you wrote this, I'm guessing you're _not_ familiar with how git's object-store works? (because a commit references its parents (back to the initial commit) by content-addressable-storage based on a hash of the contents of a commit (so you cannot "ignore" previous commits: they _have_ to exist everywhere or you'll need to rebase or squash, both of which intentionally cause information-loss), and secondarily, one does not "push files". A commit is not a file. – Dai Jan 22 '22 at 08:23
  • So, the previous commits to other branches will always be displayed in all of the branches? – jkalandarov Jan 22 '22 at 08:27
  • "previous commits to other branches will always be displayed in all of the branches" – Dai Jan 22 '22 at 08:31

0 Answers0