Git Commands & Info

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

[sourcecode language=”bash”]
sudo chown -R $USER /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules
[/sourcecode]

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

[sourcecode language=”bash”]
sudo chown -R $USER /Users/adron/.npm/*
[/sourcecode]

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

[sourcecode language=”bash”]
ssh-keygen -t rsa -C “your_email@youremail.com”
[/sourcecode]

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

[sourcecode language=”bash”]
mkdir ~/.ssh
chmod 700 ~/.ssh/
ssh-keygen -t rsa
[/sourcecode]

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”

[sourcecode language=”bash”]
git filter-branch -index-filter ‘git rm –cached –ignore-unmatch config.yml’ –prune-empty –tag-name-filter cat – –all
[/sourcecode]

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

Branch Management

Delete Local Branch

[sourcecode language=”bash”]
git branch -d the_local_branch
[/sourcecode]

Delete Remote Branch

[sourcecode language=”bash”]
git push origin –delete
[/sourcecode]

or

[sourcecode language=”bash”]
git push origin :
[/sourcecode]

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

[sourcecode language=”bash”]
git fetch -p
[/sourcecode]

Getting a Remote Branch

[sourcecode language=”bash”]
git checkout -b new_local_branch origin/existing_remote_branch
[/sourcecode]

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

[sourcecode language=”bash”]
git push origin –delete serverfix
[/sourcecode]

2 Comments

  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

This site uses Akismet to reduce spam. Learn how your comment data is processed.