Programming - useful things

This is more for me than to anyone else, really. Oftentimes I forget important commands, which I will try to put them here. Enjoy.


Git

1. Working with Git:

Before I start putting some Git commands here, I invite you to access Beej's Guide to Git. It is an invaluable resource.


To use Git you can use a GUI or the command-line. Next I'll show some commands, but if you prefer a GUI, for MS-Windows, download GitHub Desktop↗ (suggestion).

• Some basic commands.
# observe the '.' by the end!!
git clone git@gitlab.com:czekster/coolproject.git .
# note that I clone using ssh - you need to add key at gitlab! (you could clone with https as well)
# see note below: How do I add an SSH key in gitlab? - Stack Overflow

# then, modify a file on that folder, and add it to the repository:
git add .
# then
git commit -m "Message."
# then
git push
# and to get modifications on this repo, use
git pull

Check this: How to add an SSH key in GitLab↗.

• Case you deleted a file, and immediately realised it was a mistake?

#This one is easy, just do:
git checkout HEAD 
# or just git checkout 

• Remember that .gitignore will only ignore files *NOT* yet on repository. To remove those files from your repository (but not from your file system) run git rm --cached on them. Also read this thread↗.

• More useful commands:

  • Learn Git! Learn the difference between Clone and Fork
  • Create a branch in the Command Line Interface (CLI): git checkout -b
  • List remotes: git remove -v
  • Check changes (useful to check before commit!): git status

GNU/Linux

• Basic commands:

  • Adding users: adduser (this will create 'proper' users, with /home/user folders, etc.)
  • How to use scp without password: useful for scripting backups, etc. Check this link first
  • Adding user to sudoers group: (If you want it to be root... careful): usermod -aG sudo

  • Host name: hostname
  • Kernel info: lsb_release -a
  • OS-version: cat /etc/os-release
  • CPU info: lscpu
  • Memory info: free -h
  • Disks: df -h
  • Installing things: apt install htop gcc g++ make nmap unzip sysstat plocate net-tools
    • ncdu: disk usage (interesting and quick)
    • btop: better than htop, same feature