Various commands
Last active
April 19, 2019 00:26
-
-
Save rolfen/955263dfa9097b1dfd844b8ed8f6dec2 to your computer and use it in GitHub Desktop.
CheatCheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========= Settings | |
# Use nano as editor (because I'm no masochist) | |
git config --global core.editor "nano" | |
# Then creating a new repo, turn on autocrlf for the repo, to avoid lineneding shit when working cross-platform | |
git config core.autocrlf true | |
# ========= Commands | |
#<remoteName> is usually "origin" | |
#Check out single file/dir (relative/path) from different branch (feature_1). Head remains on current branch. | |
git checkout <branchName> -- relative/path | |
#Combine above with init, (shallow) fetch to only "clone" a single directory | |
git init | |
git remote add origin <repo-URL> | |
git fetch --depth 1 origin <branch> | |
git checkout origin/<branch> -- relative/path | |
#Remove last 3 commits from current branch. Use in conjunction with other commands for useful operations. Eg: "moving" last 3 commits to another branch. | |
git reset --hard HEAD~3 | |
#Add remote repository | |
git remote add <remoteName> <remoteUrl> | |
#Delete branch locally and remotely (replace -d by -D for force delete) | |
git branch -d <branch_name> | |
git push <remote_name> --delete <branch_name> | |
#Create local branch | |
git branch <branchName> | |
#Push newly created local branch to remote repo (creating it there, if needed) | |
git push -u <remoteName> <branchName> | |
#Create local branch that tracks remote branch (if we are already in the branch, then the first <branchName> argument can be omitted) | |
git branch --track <branchName> <remoteName>/<branchName> | |
#Delete remote branch | |
git push <remoteName> :<branchName> | |
#Rename branch (<oldBranchName> can be omitted for renaming current branch) | |
git branch -m <oldBranchName> <newBranchName> | |
#Git has not "remote rename" operation, so we have to delete and re-push the branch like that: | |
git push <remoteName> :<oldBranchName> <newBranchName> | |
# Fetch or push non-active branch "dev" (for remote "origin") | |
git fetch origin dev:dev | |
git push origin dev:dev | |
#"Branch in the past" | |
#You can create the branch via hash, | |
git branch branchname <sha1-of-commit> | |
#or by using a symbolic ref. | |
git branch branchname HEAD~3 | |
#Line ending settings. (autocrlf fase = ignore line ending) | |
git config --system core.autocrlf false | |
git config --system core.eol lf | |
#ignore file mode changes | |
#list settings (check that they are to your liking) | |
git config --global -l | |
git config --system -l | |
git config --local -l | |
#some things I find myself wanting to do: | |
- commit to different branch | |
- commit to two branches at once | |
- Merge all but one commit that is somewhere in the middle. Would push the commit to the top. That one might be complicated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert newlines to linux format (in file web/login.php) | |
# Explanation: -p: assume a "while input" loop, -i: edit input file in place, -e: execute following command | |
perl -pi -e 's/\r\n/\n/g' web/login.php | |
# sometimes this works | |
perl -pi -e 's/\r/\n/g' web/login.php | |
# obvioulsy we could do this instead - in theory (not tested) | |
less web/login.php | perl -p -e 's/\r/\n/g' > web/login.php | |
# echo with newline (note -e) | |
echo -e "Blah Blah\n" | |
# sync data and spindown disk sdb | |
sync | |
sudo hdparm -y /dev/sdb | |
# create ssh tunnel and use it for chrome | |
ssh -D 8080 -N me@my.server.com | |
google-chrome --proxy-server=socks5://127.0.0.1:8080 --user-data-dir=/tmp | |
# Create a remote/reverse tunnel to the local machine | |
# Note: GatewayPorts must be set to "yes" in /etc/ssh/sshd_config | |
ssh -R 8080:localhost:80 user@example.com | |
# find processes occupying TCP ports: | |
sudo netstat -lntpu | |
# or ss instead of netstat | |
# DEPRECATED: List packages and the size they each take up (Debian-based) | |
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | |
# Actually the command above only lists the "installed-size" which is actually an estimation of the disk space needed, and is extracted from package meta-information. Hence deprecation. | |
# Detach process from terminal | |
# If it's an SSH session then I can close it without killing the process after doing that | |
# For example, process rclone. Order of steps does not matter. | |
# - I believe this step is optional: redirect stdout and stderr to a file (~/rclone.log) | |
# requires https://github.com/jerome-pouiller/reredirect/ | |
reredirect -m ~/rclone.log <PID> | |
# - Send to bg and detach it | |
bg | |
disown <"rclone"|PID> | |
# run jobs to check that the job is gone | |
# - We can open another tty and reattach it there (needs reptyr) | |
reptyr <PID> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find apache config files | |
apachectl -V | |
# Get geolocation info for IP 92.3.215.10 (as JSON) | |
curl ipinfo.io/92.3.215.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add folder to PATH: | |
sudo nano /etc/paths |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment