20161001

Git Workflows

  In order to keep track of projects and other various things I find Git to be a very useful tool. Git is a set of repository interface commands, that make a great way to keep track of versions of files. Git can be complex and overwhelming even for an expert. So for my day to day use of git, I've made this set of steps as a reminder in case I forget. Feel free to use them yourself. Additionally I've added section 5 to keep my repositories tidy and small, which makes for smother working conditions.


  1. Install Git
    1. $ sudo apt-get install git-all giggle giggle-personal-details-plugin rabbitvcs-core rabbitvcs-cli rabbitvcs-gedit nemo-rabbitvcs
  2. Setup git
    1. $ git config --global user.name "John Doe"
    2. $ git config --global user.email johndoe@example.com
    3. $ git config --global core.editor gedit
    4. $ git config --list
  3. Use Git
    1. Creating new Repository with number versioning. Open a terminal and change to the repository directory cd [~/Repository/Project]
      1. $ git init (For locally created repositories)
        1. $ git clone (For remote repositories)
      2. $ git add .
      3. $ git commit -a -m "[Comment]"
      4. $ git tag -a -m "Version <#.#> v<#.#>
      5. $ git add .
      6. $ git commit -a -m "[Comment]"
      7. $ git push origin master
    2. Create new Branch.
      1. $ git checkout -b <new branch>
      2. $ git add .
      3. $ git commit -a -m "[Comment]"
      4. $ git tag -a -m "Version <#.#>" v<#.#>
      5. $ git add .
      6. $ git commit -a -m "[Comment]"
      7. $ git push origin <branch>
    3. Commit Branch.
      1. $ git status
      2. $ git add .
      3. $ git commit -a -m "[Comment]"
      4. $ git push origin <branch>
      5. $ git describe
    4. Subtree and (GitHub)Wiki Repositories
      1. $ git subtree add --prefix=<repository/path/to/subtree> <https://domain.tld/path/to/project-subtree> <remote branch>
      2. $ git subtree pull --prefix=<repository/path/to/subtree>
      3. $ git subtree push --prefix=<repository/path/to/subtree> <https://domain.tld/path/to/project-subtree> <remote branch>
    5. Filter-branch: Repeat steps 1-3 for each including master that you want to clean, then do steps 4 and 5 only once from the master branch.
      1. $ git checkout <branch name>
      2. $ git log --first-parent <branch>  --pretty=format: --no-renames --name-only --diff-filter=D | sort -u | sed -e 's/^/"/g' -e 's/$/"/g' > delete-these.txt && git add . && git commit -a -m "Added delete-these.txt." && git ls-files | sed -e 's/^/"/g' -e 's/$/"/g' > keep-these.txt && git add . && git commit -a -m "Added keep-these.txt." && git describe
      3. $ git filter-branch --force --index-filter "git rm --ignore-unmatch --cached -qr .; cat \"$PWD/keep-these.txt\" | xargs git reset -q \$GIT_COMMIT --" --tag-name-filter cat && git describe
      4. $ git checkout master
      5. $ rm -rf .git/refs/original/ && git reflog expire --expire=now --all && git gc --prune=now && git describe
The source of most of this info, and more about Git, can be found in the Git Reference Book. I've gathered some of these steps from other's blogs but don't remember all of them, so thanks to those who helped me learn git. These commands are intended for use with Linux but can be modified for Windows/Mac.