Dev Blog

./dev



Original theme by orderedlist (CC-BY-SA)


Where applicable, all content is licensed under a CC-BY-SA.
Creative Commons License

Git User Settings

Local:

$ git config user.name
abevoid
$ git config user.email
abevoid@abevoid.com
$ git config user.name abetusk
abetusk
$ git config user.email abetusk@mechaelephant.com
abetusk@mechaelephant.com
$ git config user.name
abetusk
$ git config user.email
abetusk@mechaelephant.com

Global:

$ git config --global user.name
abevoid
$ git config --global user.email
abevoid@abevoid.com
$ git config --global user.name abetusk
abetusk
$ git config --global user.email abetusk@mechaelephant.com
abetusk@mechaelephant.com
$ git config --global user.name
abetusk
$ git config --global user.email
abetusk@mechaelephant.com

Git Log

git log --decorate=full --graph

Merge Branches and Keep DAG History

git checkout -b alt-branch
...
git commit
git checkout fin-branch
git merge --no-ff alt-branch

Creating and Deleting Branches

git checkout -b x-branch
...
git commit 
git push -u origin x-branch
git checkout release
git merge --no-ff x-branch
git commit 
git push
...
git branch -d x-branch
git push origin :x-branch

Destroy Local Changes To Files

git fetch ; git reset --hard origin/release

Move Local Changes to New Branch

git branch newbranch
git reset --hard origin/master
git checkout newbranch

Create a branch but don't switch to it. Remove local commits back to origin/master. Now switch to the new branch and continue work.

Comparing Changes

Local changes since last commit:

git diff

Two commits ago:

git diff HEAD^^

or:

git diff HEAD@{2}

Restore File

Single file:

git checkout -- fn

Everything in a repo:

#!/bin/bash

for f in `git ls-files -d`
do

  echo restoring $f
  git checkout -- $f

done

Caching Git Password

git config --global credentail.helper 'cache --timeout=3600'

Clear Git Credential Cache (Clear Git Cached Password)

git credential-cache exit

Tracking Remote Branch

git remote add origin https://github.com/user/repo.git
git remote -v

Checking Out Submodules

git clone --recursive https://github.com/user/repo
git submodule update --init --recursive

Applying Inverse

Create (add) a new commit that applies the inverse operation of the given <SHA>.

git revert <SHA>

References

2017-02-10