Git Lecture Notes

Topics Discussed

SSH

Installing ssh

sudo apt-get install openssh

Connecting to server

$ ssh username@hostname

Public key authentication

ssh-keygen -t rsa The private key is at ~/.ssh/id_rsa while the public key is at ~/.ssh/id_rsa.pub The server needs your public key to authenticate the connection.

Version Control

Git Basics

This is just a simple walkthrough. You are encouraged to try out these steps on your own.

A Little More

Little of git-jargon

Read more over here

Git Workflow

Fork, Merge, Pull

This is what Github follows. People create their own fork version of the repo, and send back pull requests

Shared Repository

A single repository shared among various people can be used successfully if the project is closed, and has known developers This is mainly for organizations and trusted developers

Branching Model

Mainly from here
Topics include branches, stable, hotfix, release, development, feature branch etc.

Github

Some other things

A few more git commands

To install any of the packages mentioned above, just run sudo apt-get install package in ubuntu.

Redmine

Commit Messages Editing

When you make commits on git, it uses your default text editors to type the commit message. This is set to vim in Windows and Linux. Linux folks can change it to anything else by setting the $EDITOR variable by the following command: export EDITOR=nano (Replace nano with the editor of your choice like gedit geany etc)

You can also save the setting in your git global configuration, by : git config --global core.editor "nano"

As per this question on SO, you can use Notepad++, or notepad etc on git on Windows as well.

git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Take care about the slashes, and the path to your editor of choice. Don’t use notepad, it screws with the newlines.

Vim

If you’re stuck with vim for some reason, do the following in the commit window

  1. Press i to go to insert mode
  2. Type your commit message
  3. Press Esc
  4. Type :wq. The colon is important
  5. Press Enter
  6. That’s it, your commit should be successful

Remember, an empty commit message aborts the commit. Also the best way to commit easily is:

git commit -m "Commit Message Here" to just type the commit message on the command line, and leave out all the hassle of the editor

To learn how to use vim effectively, type ‘vimtutor’ in terminal.

Faster Git Resources

Git allows you to defined aliases for certain commands. These faster ways of using git create several additional commands for git, such as git release, and ga etc

Also see tig, which is a cli repo browser for git.

Resources on Git