Git - Part 2: Repositories

Create a repository

Initialize a new Git repository

git init

Add and Commit to a repository

Stage Single file

git add index.html

Stage Multiple files

git add index.html index2.html

Stage All (new, modified, deleted) files

git add -A

Stage All (new, modified, deleted) files

git add --all

Stage All (new, modified, deleted) files

git add .

Stage Modified and Deleted files only

git add -u

Stage New and Modified files only

git add --ignore-removal .

Commit to repository

git commit -m "This is commit message"

Exercise

  1. Create a new file index.html and add some content
    touch index.html
  2. Add index.html to Git
    git add index.html
  3. Check git status (see: index.html is ready for commit)
    git status
  4. Open index.html and change some of the content
    vi index.html
  5. Check git status (see: previous index.html is still ready for commit; index.html is modified)
    git status
  6. Commit changes
    git commit -m "Initial commit"
  7. Check git status (see: index.html is still modified)
    git status
  8. Add index.html
    git add index.html
  9. Commit index.html
    git commit -m "Content is changed"
  10. Check git status (see: nothing to commit)
    git status
  11. Check git log (see: both commits)
    git log

Package repositories on Ubuntu Server

Package repositories

Update the package repositories from sources with the latest versions

sudo apt-get update

A list of repositories, that the server will check for packages, is stored at /etc/apt/sources.list

cat /etc/apt/sources.list

Extra repositories can be added to /etc/apt/sources.list.d

Package information

Search for available packages (eg. mysql); to search only by the package name, use -n tag.

sudo apt-cache search mysql
sudo apt-cache search -n mysql

Get the package information (eg. mysql-server-5.6)

sudo apt-cache show mysql-server-5.6

Install/uninstall a package

Install a package || without prompting use tag -y || for quiet install use tag -qq

sudo apt-get install -y mysql-server-5.6

Uninstall a package ('purge' removes the configuration, 'remove' removes only the package)

sudo apt-get purge mysql-server-5.6

After uninstalling use autoremove to remove any dependencies that are not in use by other packages

sudo apt-get autoremove

List all installed packages

Get a list of packages installed locally (the -v tag "inverts" grep to return non-matching lines)

dpkg --get-selections | grep -v deinstall

Get a list of a specific package installed

dpkg --get-selections | grep mysql

Alternatively, simply use

dpkg -l

Get just the packages which were expressly installed (not just installed as dependencies)

aptitude search '~i!~M'