Git Commands & Info

HomeDocs >

The latest of my forgetful commands. A few chmods for running npm and cutting back on arbitrary sudo needs.

sudo chown -R $USER /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules

…and every once in a while the stupid npm directory will get hosed up, which can often be fixed with.

sudo chown -R $USER /Users/adron/.npm/*

One command I always forget is what the switches are for creating an ssh key.

ssh-keygen -t rsa -C "your_email@youremail.com"

There is also the case of making the directory with appropriate permissions to then create the ssh key.

mkdir ~/.ssh
chmod 700 ~/.ssh/
ssh-keygen -t rsa

More information, specific to github, can be found in this documentation.

Brian McClain (@BrianMMcClain) added from the comments below:

If there’s ever a file you need to remove from git history for whatever reason (accidentally included a password or API Key, removing large files, etc), the below will remove it from the history of every branch and every tag. For example, to remove a file named “config.yml”

git filter-branch -index-filter 'git rm –cached –ignore-unmatch config.yml' –prune-empty –tag-name-filter cat – –all

For more info on this command, check out the link to the github doc.

Branch Management

Delete Local Branch

git branch -d the_local_branch

Delete Remote Branch

git push origin --delete

or

git push origin :

To synchronize your branches once a delete has occurred you sometimes may need to issue the following fetch command.

git fetch -p

Getting a Remote Branch

git checkout -b new_local_branch origin/existing_remote_branch

…and last but not least, the forgotten remote branch delete command.

git push origin --delete serverfix

2 thoughts on “Git Commands & Info

  1. One I hate that when I have to use, but always need to look it up. If there’s ever a file you need to remove from git history for whatever reason (accidentally included a password or API Key, removing large files, etc), the below will remove it from the history of every branch and every tag. For example, to remove a file named “config.yml”…

    git filter-branch -index-filter ‘git rm –cached –ignore-unmatch config.yml’ –prune-empty –tag-name-filter cat – –all

    ref: https://help.github.com/articles/remove-sensitive-data

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s