Skip to content

Instantly share code, notes, and snippets.

View hugoduraes's full-sized avatar

Hugo Durães hugoduraes

View GitHub Profile
ssh -f -T -N -L <remote port>:<local IP>:<local port> <username>@<remote ip>
```
# Rename branch locally
git branch -m old_branch new_branch

# Delete the old branch
git push origin :old_branch

# Push the new branch, set local branch to track the new remote
git push --set-upstream origin new_branch

If you have committed junk but not pushed

# deletes the commit but it will leave all your changed files "Changes to be committed"
git reset --soft HEAD~1

# deletes the commit and gets rid of any changes to tracked files
git reset --hard HEAD~1

If you already pushed and someone pulled

Add a new tag and push it

git tag new_tag old_tag
git push --tags

Then delete the old tag from remote and local

git push origin :refs/tags/old_tag
git tag -d old_tag

To delete a local branch

git branch -d the_local_branch

To remove a remote branch

git push origin :the_remote_branch

If you want to delete a local tag then you would do

git tag -d the_local_tag

But if you want to delete remote tag, then the syntax is a little different

git push origin :refs/tags/the_remote_tag
// document.body.scrollTop alone should do the job but that actually works only in case of Chrome.
// With IE and Firefox it also works sometimes (seemingly with very simple pages where you have
// only a <pre> or something like that) but I don't know when. This hack seems to work always.
var scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
// Grodriguez's fix for scrollHeight:
// accounting for cases where html/body are set to height:100%
var scrollHeight = (document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight;
// >= is needed because if the horizontal scrollbar is visible then window.innerHeight includes
@hugoduraes
hugoduraes / git-delete-file-from-history.md
Last active November 30, 2016 10:36
Deletes file from git history

Execute the following command replacing /path/to/sensitive-file by the file you wish to remove from git history:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch /path/to/sensitive-file' --prune-empty --tag-name-filter cat -- --all

Reset

You can reset the commit for a local branches using git reset

To change the commit of a local branch:

git fetch
git reset origin/master --hard
@hugoduraes
hugoduraes / create-superuser.md
Created November 30, 2016 10:33
Create user with root privileges and adds an SSH key to it

On the remote machine:

sudo su -
useradd <username> -m -s /bin/bash
echo '<username> ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
mkdir -p /home/<username>/.ssh
touch /home/<username>/.ssh/authorized_keys
chown -R <username>:<username> /home/<username>/.ssh
chmod 700 /home/<username>/.ssh