banner



How To Update Fork To Master

Like nearly everyone in the DevOps world, I apply GitHub, not because I like it, only because everyone uses it. In fact, I dislike it, because information technology's confusing by design. Its misleading language excludes users, rather than welcoming them. To utilize it, you have to forget the actual pregnant of words in English language, or even their technical meaning, and employ them equally though they are capricious strings.

Worst of all, because most people memorize a command sequence without fully agreement how it works, when something goes wrong, it'southward almost incommunicable to troubleshoot.

Okay, plenty ranting.

I just discovered a solution to ane of the problems I encounter oftentimes, so I want to share it with yous. My utmost thanks to PowerShell MVP and Principal Engineer – Community Applied science for Chef, Steven Murawski for showing me the solution and letting me attempt information technology by myself (twice) while he was standing nearby in case of disaster. If this solution works for yous, tweet your thank you to Steven.

Your Fork is Outdated

Here'south the trouble. Yous create a fork (an online copy) of a repository and a clone (a local copy on disk) of your fork. You spend some fourth dimension examining the files and interpreting the code. So, when you're ready to work, you find the message on your fork.

"This co-operative is due north commits behind (source-repo)."

clip_image001

That makes sense. While you were working, other people were working, likewise. And then, yous want to synchronize your branch of your fork (the online copy) and its clone (the disk copy) with the files in the source repository.

This happens and then often and it's so predictable that you'd think there would be a Sync button or something like information technology, but in that location's not.

As well, if you effort something rational, like opening your Git Shell (I apply Git for Windows with posh-git) and trying to fetch/merge or pull (or push or anything else yous tin think of), that won't work, because, by default, those commands synchronize your clone (on disk) with your fork (online) and they're already in sync. Yous need to synchronize your fork/clone with their source.

Remote: A link to the Source

1 solution, the i I had been using, is to copy whatsoever files yous've changed to a different directory, delete your fork, delete your clone, and so re-fork and re-clone, and motility the changed files dorsum in. Yeah, I've done this. Whatsoever it takes.

The correct Steven-Murawski-canonical solution is to create a remote , that is, a named link to the source repository, in your clone (on disk). This lets yous become and send things from your clone to the source repo.

A remote is but another name, alias, or nickname for the URL to an online repository. In any command that yous utilise the name of the remote, you tin can utilize the URL, and vice versa.

Actually, you lot already accept ane remote; a remote to the fork, although you lot might not accept noticed. When yous clone (brand a deejay copy) an online repo, the clone control automatically creates a remote to the repository that you lot cloned, typically your fork. That remote is named origin.

To see your remotes, utilise git remote.

C:\Github\dbatools [master]> git remote origin        

To see the URL of the remote, add -v (for verbose). These are remotes to my fork, so they have my username, juneb, in the URL.

C:\Github\dbatools [master]> git remote -5 origin https://github.com/juneb/dbatools.git (fetch) origin https://github.com/juneb/dbatools.git (push)        

By default, when y'all apply git fetch, git merge, git pull, or git push, git uses the origin remote. Equally a result, it gets stuff from or sends stuff to the fork that you cloned.

And then, to get or send to the source repo, y'all demand another remote.

Update your clone and fork

To go all changed files from a source repository and copy them to the clone, and so to the fork.

  1. On GitHub.com, on the folio for the source repository (not your fork), copy the URL of the source repo. It's the same URL that you would employ to clone the source repo.

    clip_image003

  2. In your shell, navigate to the directory with the clone, and utilize the post-obit control to create a remote to the source repo.
    git remote add together <name> <copiedURL>

    For case:

    git remote add together upstream https://github.com/ctrlbold/dbatools.git

    The name is capricious. You can use any valid string for the name of your remote. The traditional name of a remote to the source repository is 'upstream' which makes nearly as much sense as the rest of the words in GitHub. In this apply, it is a name, not a direction. Regardless, I use it, because people recognize information technology.

  3. Become (fetch) and merge changes from the source repo to your clone. All names, including the remote name and co-operative proper noun, are case-sensitive.
    git fetch <nameOfRemote> git merge <nameOfRemote>\<branch>

    For example,

    git fetch upstream git merge upstream\master
  4. Transport the changes from your clone (on disk) to your fork (online). You don't need to qualify this command with a remote, because the "origin" remote is the default.
    git button

Now, your clone and fork have the same content:

C:\Github\dbatools [master]> git status On co-operative master Your branch is upward-to-date with 'origin/master'.  naught to commit, working directory clean        

And, miraculously, your co-operative is "even with main".

clip_image004

Thanks, Steven! It works!

To sync again

If you lot go along to work on this project and your fork becomes outdated again, you lot already take a remote to the source repo. And then, just repeat the fetch, merge, and push. There'south no need to recreate or update the link to the remote repo.

git fetch upstream git merge upstream\primary git button

Not too tough. Having this solution makes my GitHub live a lot easier. I still don't similar it, merely I use it.

June Blender is a engineering evangelist at SAPIEN Technologies, Inc. and a Windows PowerShell MVP. You can reach her at juneb@sapien.com, follow her on Twitter at @juneb_get_help , and notice her GitHub repos at https://github.com/juneb.

How To Update Fork To Master,

Source: https://www.sapien.com/blog/2016/05/16/github-how-to-update-your-fork/

Posted by: cooperdaverneat.blogspot.com

0 Response to "How To Update Fork To Master"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel