Skip to content

Instantly share code, notes, and snippets.

View hugoduraes's full-sized avatar

Hugo Durães hugoduraes

View GitHub Profile

Delete local branches not on remote

git branch -vv | grep ': gone]' |  grep -v "\*" | awk '{ print $1; }' | xargs git branch -d
@hugoduraes
hugoduraes / README-Template.md
Created July 20, 2017 10:22 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@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

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 / 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
// 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

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

To delete a local branch

git branch -d the_local_branch

To remove a remote branch

git push origin :the_remote_branch

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

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