Reputation: 77
I am pretty new to Github, I've forked a project, committed some modifications and then made a pull request to the main project.
If, while waiting that my pull request is merged/refused, I would want to work on another issue of the main project... how can i do to not interfere with my older code? Should i do another fork of the main project?
Thank you very much and sorry for the noob question.
Upvotes: 2
Views: 628
Reputation: 1740
You can checkout to new branch.
If You don't need changes from actual branch, you can back to main branch e.g. master
, and create new branch.
But if you need changes from branch, where you are working now, create new branch from this branch, where you working now.
Upvotes: 2
Reputation: 7872
A fork is a full copy of a repository, and you can't fork a repository twice. What you can do is working on branches.
Git branches are isolated space where you can work without interfering with other branch's code.
So here is a simple walkhough
Since you most likely worked on you master branch (the dfault one), we need to create a new branch and then moving back to the main repository state (so your commits won't be on this new branch)
git checkout -b <new_branch_name>
git reset --hard <old_commit_id>
On your new branch, you now are on the same state as the main repository.
// Do some codding stuff
git add file1 file2
git commit -m "Issue #xxx resolved"
git push <your fork remote> <new_branch_name>
Notice that we now push to the we no longer push to master, otherwise it will conflict, because the commit tree is not the same.
Now, you can open a pull request from your new branch.
// it show all the branch you do own
git branch
// Switch to <branch_name>
git checkout <branch_name>
When working on a forked project (or not), it is better to keep the master branch at the same commit as the main project, so, you can create as much branch as you want from master without having to rolling back to an older commit.
Upvotes: 1