nullpointer17
nullpointer17

Reputation: 77

Github working on fork while waiting for pull request

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

Answers (2)

MatWdo
MatWdo

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

Anthony Raymond
Anthony Raymond

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

Create a new branch

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>
  • First instruction create a new branch at the point you were on the previous branch (usualy master).
  • Second instruction revert the code back to a defined commit ID (you want the last commit on the main repository).

On your new branch, you now are on the same state as the main repository.

Do Some work

// 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.

Open a new pull request

Now, you can open a pull request from your new branch.

navigate through branches

// it show all the branch you do own
git branch

// Switch to <branch_name>
git checkout <branch_name>

Tips

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

Related Questions