1

I am working on a project using git where I've been assigned two tasks. Let's assume task A and task B.

I started by forking the project and created a branch named A at this point I was not aware I had to do task B. After forking the project I've cloned the project to my local pc.

Next I ran following command:

git checkout -b A -- created branch A

I made changes to project as per the requirement then I did the following

git add *

git commit -m "message"

git push origin A

Now I was assigned task B for which I created the branch named B.

git checkout -b B

Made changes as per the requirements and committed those changes to branch B.

Now the issue is Branch B contains changes also made in A, instead it should follow the main branch plus changes required as per task B. How can I fix this issue? Branch B should follow main branch and changes as per task B on branch B.

I tried git checkout main but no such branch exist.

3
  • Before you go any further with this question, you need to decide: are you doing everything directly on GitHub? (This is difficult and probably a bad idea.) Or: did you clone the GitHub repository to your own machine, e.g., a laptop? (This is usually the way to go.) If you did clone your GitHub fork, there are now three repositories involved: two on GitHub (the original and your fork) and a third on your laptop. Commented Jun 1, 2021 at 7:58
  • This is important because every repository has its own branch names. When you work with multiple repositories like this, you will share commits but you won't share branch names. Commented Jun 1, 2021 at 7:59
  • So, given that (from your question) there are three repositories, it's now important to say: "I have branch B on my laptop" or "I have branch B on my GitHub fork" or whatever. You might (or might not) use the same names in the GitHub fork as on your laptop, but these are different branches! Commented Jun 1, 2021 at 8:00

1 Answer 1

1

Try with this:

 # Checkout the master branch git checkout master # Create a fix branch git branch task-b-fixup # Get history of branch task-b git log --oneline --graph --decorate task-b # Cherry pick commits from task-b by repeating the following command git cherry-pick {{task-b commit hash}} 

Now, if you want, you could destroy the old task-b branch.

Sign up to request clarification or add additional context in comments.

3 Comments

I can't checkout master branch I am not sure why. I am getting an error fatal: not a git repository (or any of the parent directories): .git.
That error occurs when the .git folder is not present! Please post the output of the tree -d command.
Sorry I was not in the correct directory now I can switch to master branch. Let me try out the solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.