Github: learning to work with a fork correctly

Sooner or later in the life of every mmm … Malthusian, let’s say .. there comes a moment when you need to learn how to work with the Git like a human being. In particular, engage in gardening – grow branches, graft them, cut them, and so on.

Well, I’m an amateur gardener and always pushed everything into a master. I drove a tank to the store for bread, so to speak.

But the time has come when it is important that the shoots grow in the right direction … Let’s say we made a fork (on the github website, click the button on the top right) and ..

1) clone it to local
git clone<my_username>/<fork>.git
git clone<my_username>/<fork>.git
2) connected to the main rep (in order to later roll updates from there)
git remote add upstream git://<user>/<repka>.git
3) create branch
git branch <branch_name>

4) made the branch active
git checkout <branch_name>
(you can immediately make a branch and make it active: git checkout -b <branch_name>)
5) well, we programmed cool features on our local computer. preparing a commit:
git add <file_name>
git commit -m "<comment>"
6) tested and published in our branch remotely:
git push -f origin <branch_name>

Meanwhile, the original turnip also did not stand still and the wildest updates appeared there as well. How to update your turnip? To start:

look at the intricacies of branches (-all)

git remote -v
(we check where and where the ears of our escape grow). When executed, this is what it shows:

origin<my_username>/<fork>.git (fetch)
origin<my_username>/<fork>.git (push)
upstream<dev_user>/<original>.git (fetch)
upstream<dev_user>/<original>.git (push)

origin – this is what we have on the local; our clone project. upstream is work with the parent project. At the end, in brackets, they write what we can do with them – fetch (pull out) and push (push there from the clone). Btw, git pull – it’s basically two commands in one: git fetch и git merge.

Now we update the master of our fork:

git fetch upstream

git checkout master

git rebase upstream/master

Next, switch to your branch and make rebase:

git checkout <branch_name>

git merge master

Well, we throw the new version to the remote:
git push --set-upstream origin <branch_name>

Congratulations, you made it!

This entry was posted in Git (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs are not allowed.
🇷🇺 Комментарии со ссылками удаляются автоматически.