How to Upload Fork to Master in Git

How To Properly Fork a Github Repository

Open source programming is all about being able to make your own changes to code others accept written. To exercise that, you must branch off from the main repository, commonly chosen "forking" the repo, but information technology can be complicated if you don't do information technology properly.

While this specifically applies to Github, as information technology is by far the biggest identify for open source collaboration, the aforementioned principles will hold for Git repositories forked from any source. Github just has actress tools that make some tasks easier, just if you prefer Git commands, we will testify those also.

Forking From Github

If yous're using Github, the easiest method to fork a repository is to click the "Fork" push, which volition automatically make a new repository in your business relationship and gear up the remotes when you clone it. This will also brand it show up in the "forks" tab of the source repo, and will evidence on your repo as "forked from 10."

If you don't want that showing up, or aren't using Github, y'all'll demand to clone manually.

If you are cloning information technology yourself, make sure to clone the repository properly rather than doing "Download Naught." If you don't clone it through Git, it won't copy over the version history and won't exist configured as a Git repository.

Configuring The Fork's Upstream Remote

If y'all forked the repository from the Github website, the origin remote will point to your fork. However, information technology's also useful to exist able to pull from the original source repository, called the "upstream." If they make changes, you'll probably want to merge or rebase with the upstream remote.

Github has tools built in to do this automatically, so you don't have to practise this part, but if yous want to use CLI tools, yous'll demand to add back the original repo as a remote called "upstream":

git remote add upstream https://github.com/writer/original.git

Forking From Git CLI

If you lot downloaded or cloned it from elsewhere, your repository will still be linked to the remote you cloned it from. This is likely what has happened if yous downloaded a repo before intending to fork it. Luckily, this is perfectly fine, and you will simply need to configure it yourself.

If you desire to integrate new changes from the source, you lot'll yet want the source remote, but it shouldn't exist the default "origin" remote. So, you'll want to rename the default remote from "origin" to "upstream."

git remote rename origin upstream

And then add your ain remote as the new "origin," which you will probably demand to make manually if you programme on pushing information technology back to Github:

git remote add origin https://github.com/author/ForkName

One time that's washed, you'll probably need to set the default remote for each branch to your fork:

git branch --set-upstream-to origin

And button to origin, which will upload the files to your new repository.

Updating With New Changes

If you forked from Github, ane of the squeamish features is that it keeps track of the upstream source and allows you to perform merges through the Github website. It'll prove you when information technology's up to date, and when it isn't, you'll take the option to merge.

If you desire to practise information technology through the Git CLI though, there is a better way. Rebasing is like to merging, but keeps a flat commit heirarchy and doesn't atomic number 82 to unnecessary merge commits. Most of the time, you'll want to rebase when integrating upstream changes, but this is up to y'all. Merging is also a valid strategy, especially if yous're not merging very ofttimes.

To integrate changes, you lot will need to fetch the upstream remote, checkout the chief branch, and rebase to upstream/master.

git fetch upstream  git checkout chief  git rebase upstream/master

Afterwards this, you may need to strength push if this is the kickoff time rebasing:

git push -f origin master

Making Pull Requests

If y'all forked from Github, this is also easy. Y'all can merely press "Contribute" and it will automatically open a pull asking.

If non, the process is still uncomplicated. Head to the upstream repository, and under the "Pull Requests" tab, select "New Pull Request."

Then, y'all will need to select "compare across forks" and notice your fork repository. Select the branches you desire to merge, and click "Create pull request."

You can continue working on your fork, and merging in pull requests as needed. If you're doing this a lot, you lot may want to consider setting up your own branches locally for your features, and and so merging into the target upstream branch when you want to make a PR. This can help with keeping PRs on topic and focused on one feature co-operative at a time.

troutonbessalp.blogspot.com

Source: https://www.cloudsavvyit.com/14640/how-to-properly-fork-a-github-repository/

0 Response to "How to Upload Fork to Master in Git"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel