git

Version control system.

Tips

Use fetch and merge instead of pull (see).

Commands

Life Cycle of a change

  1. Run git status.
    • Possibly run git stash to hide uncommitted changes.
  2. Create Branch: git branch <new_branch> <current_branch>.
  3. Switch to new branch: git checkout <new_branch>.
  4. Make changes...
  5. Run git status.
  6. Stage all changes to tracked files: git add -u (or git add -A to add new files also).
  7. Run git status.
  8. Commit changes: git commit -m "[comment]".
  9. Ensure current branch is up to date: git fetch.
  10. Merge branches; At each stage resolve any conflicts:
    1. Switch to the parent branch: git checkout [parent_branch].
    2. Ensure branch is up to date: git fetch followed by git merge origin.
    3. Switch to the new branch: git checkout [new_branch].
    4. Merge parent with new_branch: git merge [parent_branch]. Best to try merging this way first.
    5. Switch to the parent branch: git checkout [parent_branch].
    6. Merge new_branch with parent_branch: git merge [new_branch].
    7. Publish your changes: git push.
  11. Delete new branch: git branch -d [new_branch].

Setup

Use git init: to create a new repository.

Add a .gitignore file to the repositories root directory to exclude files from Git (example).

Configuration file

~/.gitconfig:

[user]                                                                          
    name = Paul Ahern                                                           
    email = ahernp@ahernp.com                                                   
[merge]                                                                         
    tool = vimdiff                                                              
[core]                                                                          
    editor = vi                                                                 
[alias]                                                                         
    co = checkout                                                               
    ci = commit                                                                 
    st = status                                                                 
    br = branch                                                                 
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short     
[color]                                                                         
    ui = auto                                                                   
[push]                                                                          
    default = simple                                                            

# Use ssh instead of https                                                      
[url "git@github.com:"]                                                         
    insteadOf = https://github.com/