How to sync/update forked git repository with upstream?

中文版: https://www.peterdavehello.org/2014/02/update_forked_repository/

I found the origin post in Chinese is more popular among all the posts, so just rewrite it in English now :)

Once you forked a repository on GitHub, the commit history from the upstream will stay at the moment you forked it, sometimes we’ll need to update it, so that the parent of our commit won’t be so old, which can help us have a better look, easier to trace git commit history, and prevent some potential or known conflicts, maybe you have other reasons, anyway. This method can also sync a repository between different git servers.

NOTE:
If you forked repository is behind the upstream repository for more than 1k commits and the repository is fat, you can consider to delete your forked repository and re-fork the origin one, it may be faster and more efficient.

Let’s start it.

First, if you didn’t have the repository locally, you have to clone the forked repository to local, you can set the clone depth to save the bandwidth and disk space usage:
$ git clone --depth 1 https://github.com/user/repo.git

(Replace the url to your forked repository)

Once you cloned it, check its ‘remote’, usually you’ll get only one remote after clone, like this:
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)

Now we should add another ‘remote’ – the origin upstream, so that we can pull the updates from, in this case, use read-only git protocol will be faster, more efficient (but note that some firewall may not allow that protocol, so you’ll need to use https in that case):
$ git remote add upstream git://github.com/otheruser/upstreamRepo.git

PS: ‘upstream’ is the name I gave it, you can give it another name as you want.

To verify new added remote, let’s check it again, you should have two remotes now:

origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream git://github.com/otheruser/upstreamRepo.git (fetch)
upstream git://github.com/otheruser/upstreamRepo.git (push)

Now we can start the “update” works, I assume the branch you’re going to update is the master branch, if you are going to update a non-master branch, just checkout to the branch you want, but don’t forget to change the branch from the below examples!

If your branch is only behind the upstream, no any “ahead” commits(which means you didn’t commit any new things on the same branch came from upstream), you can directly pull the updates from upstream:
$ git pull upstream master

If your branch also contains your own commits, you should better pull with “–rebase” parameter:
$ git pull --rebase upstream master

Now, almost done, if there is no error or conflicts(we don’t discuss conflicts here), push your master to origin remote, then you’ll found that your forked repo is fresh again:
$ git push origin master

Remotely shutdown/restart Windows via Linux on Debian/Ubuntu based Linux

Need samba-common package first, install via apt:

$ sudo apt-get install samba-common

Then use this command to shutdown the computer remotely(replace ip, username and password with your own):

$ net rpc shutdown --ipaddress ip --user username%password

Add -r if you want to restart, not shutdown:

$ net rpc shutdown -r --ipaddress ip --user username%password

After execution, here is the success message:

Shutdown of remote machine succeeded

If receive these messages below means something failed:

Could not connect to server 192.168.1.55
Connection failed: NT_STATUS_IO_TIMEOUT
Connection failed: NT_STATUS_RESOURCE_NAME_NOT_FOUND
Could not initialise pipe winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND

There are many functions provide by net [rpc], like:

net rpc audit Modify global audit settings
net rpc info Show basic info about a domain
net rpc join Join a domain
net rpc oldjoin Join a domain created in server manager
net rpc testjoin Test that a join is valid
net rpc user List/modify users
net rpc password Change a user password
net rpc group List/modify groups
net rpc share List/modify shares
net rpc file List open files
net rpc printer List/modify printers
net rpc changetrustpw Change trust account password
net rpc trustdom Modify domain trusts
net rpc abortshutdown Abort a remote shutdown
net rpc shutdown Shutdown a remote server
net rpc samdump Dump SAM data of remote NT PDC
net rpc vampire Sync a remote NT PDC’s data into local passdb
net rpc getsid Fetch the domain sid into local secrets.tdb
net rpc rights Manage privileges assigned to SID
net rpc service Start/stop/query remote services
net rpc registry Manage registry hives
net rpc shell Open interactive shell on remote server
net rpc trust Manage trusts
net rpc conf Configure a remote samba server

Check man rpc for more details!

Mute certain tab in Google Chrome/Chromium

Open chrome://flags/#enable-tab-audio-muting and enable “Enable tab audio muting UI control” option, then restart your browser.
chrome-enable-tab-audio-muting

Now we can have mute option on each tab:
chrome-enable-tab-audio-muting-menu

After that, there will be a muted icon on the tab, and if you want to unmute it, there is also an unmute option in the menu of the tab.
chrome-enable-tab-audio-muting-muted

Very useful when surfing to some noisy websites!

BTW , the demo screenshots came from the trailer of Transcendence, a very very awesome movie!
[youtube=https://www.youtube.com/watch?v=VCTen3-B8GU]

openvz template re-pack

To create a whole new openvz template is a little bit complex, use already exist template to create a new version is much easier.

Refererce:
https://techanarchy.net/2015/01/proxmox-custom-openvz-templates/
https://raymii.org/s/tutorials/OpenVZ_Proxmox_Container_to_Template.html

Actually, I’ll remove logs under /var/log/ before re-pack the template.

Hint:
Use pigz to compress the template can save your time, reference:
Use multi-threads to compress file(s) when tar-ing something