DEV Community

Dawid
Dawid

Posted on • Updated on

Simple work with Git Fork

"A fork is a copy of a repository that you manage. Forks let you make changes to a project without affecting the original repository."

Link for github docs

On the start

We have 2 repos

  • original github/OWNER/original
  • forked github/YOU/forked

In forked repo we can check our settings

$ git remote -v
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
Enter fullscreen mode Exit fullscreen mode

On the next we need to add original repo as upstream

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
Enter fullscreen mode Exit fullscreen mode

Now we should see

$ git remote -v
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
Enter fullscreen mode Exit fullscreen mode

Get changes from original to forked

git fetch upstream
git checkout main
git merge upstream/main
Enter fullscreen mode Exit fullscreen mode

Creating Pull Request from forked to original

# FORKED repo

# make changes

git add .
git commit -m "message"
git push
Enter fullscreen mode Exit fullscreen mode

Then go to forked repo on github and create Pull Request.

PR on github

Workflow

To keep workflow clean:

✅ original → forked

⛔ forked → original (do it only when you are sure what are you doing!)

Discussion (1)

Collapse
siimonstark profile image
Justin

Just shared this with my class. Really great and easy to follow breakdown :)