Files

git add . — adds everything to index
git commit -am "Comment" — makes commit of all changes with specific comment. (New files are NOT auto added!)
git checkout -- path/to/file — undoes uncommitted changes to specific file
git checkout -- . — same as above for full repository
git diff-tree --no-commit-id --name-only -r abcdef — lists names of files for a specific commit
git log -p filename — lists changes history for specific filename (provide . filename to see changes for whole project)
git diff — lists unstaged changes
git diff --cached — lists staged changes
git reset path/to/file — removes file from “Changes to be committed”
git clean -f — removes all unstaged files
git checkout changes -- /php/code.php — retrieves /php/code.php file from changes branch

Branches

git checkout -b new-branch — creates new branch with name “new-branch” and switches to it
git merge master — merges into current branch from branch with name “master”. Optional --no-commit can be passed in order not to commit after merge (In case you need some more changes for example)
git log new-branch..master — lists all commits on branch “master” which are not in branch “new-branch”
git branch -d branch-name — deletes branch

Remotes

git remote add another git@localhost:/git/repo.git — creates new another remote
git remote rm origin — removes origin remote
git remote rename origin new-origin — renames origin remote to new-origin
git remote set-url origin git@localhost:/git/repo.git — changes url associated with origin remote

Stashes

git stash list — list all stashes
git stash — stashes uncommitted changes
git stash save "Stash message" — stashes uncommitted changes with specific message
git stash save --keep-index "Stash not indexed" — same as above, but will only stash not added to index changes (Changes not staged for commit)
git stash pop — applies stashed changes (And removes stash state from stash list)
git stash apply — same as above, but doesn’t remove stash state from stash list
git stash clear — clear all stash states from stash list
git stash drop stash@\{0\} — deletes stash with stash@{0} name (From git stash list). Don’t forget to escape curly brackets!
git stash show -p stash@\{0\} — describes stash changes (Output similar to git diff)

Config

git config --list — list all config values
git config config-key value — sets “value” as value for config key “config-key”
git config --unset config-key — deletes config key “config-key” and its value
git --edit — edit config as text document
--global option can be used for all config commands in order to access global config (Not current repository only)

Share Button

Users & groups

cat /etc/passwd – list system users
cat /etc/group – list system user groups
useradd user – create new user
passwd user – edit user password (Skip username to edit your own password)
usermod -g group user – changes user’s primary group
usermod -a -G group user – add existing user to secondary group

Archives

tar -zcf archive.tar.gz dir1/ dir2/subdir file.txt – create new archive with name archive.tar.gz, include dir1/, dir2/subdir, file.txt directories & files
tar -xf archive.tar.gz -C extract/to/dir – extract files from archive.tar.gz to extract/to/dir (Omit destination path & -C option to extract to same directory)

zip

zip -r archive.zip dir1/ dir/subdir file.txt – create new archive with name archive.zip, include dir1/, dir2/subdir, file.txt directories & files
unzip archive.zip -d extract/to/dir – extract files from archive.zip to extract/to/dir (Omit destination path & -d option to extract to same directory)

Software

dpkg --list | grep php – list installed packages, optionally filter by name with grep
apt-cache search kde – search for packages available to install
apt-get install firefox – install package
apt-get remove --purge skype – uninstall package and all of its configuration files (To retain configuration files, skip --purge option)
apt-get autoremove – remove all orphaned, not used packages (Packages, which were used as components for other packages, now all removed)

Hardware

lsblk – list all devices (Including CD-Roms, USB flashes etc.) and mount points (If mounted)
mount /dev/sdb /mnt – mounts /dev/sdb/ device to /mnt path (Path must exist)
umount /dev/sdb – unmounts device

Processes

ps aux | grep nginx – list all running processes, optionally filter by name (Process name, command will be filtered) with grep
kill 123 – kill process with PID 123 (PID can be retrieved with ps aux)
pkill nginx – kill process by name

Mysql

mysqldump --host=localhost --user=db_user --password=db_password db_name | gzip > db.sql.gz – creates dump of db_name database, logging in with provided credentials and gzips it to db.sql.gz file
zcat db.sql.gz | mysql --host=localhost --user=db_user --password=db_password db_name – imports gzipped database dump to db_name database

Share Button