November 20, 2015

Useful git commands cheat-sheet

git commit --amend -m "New commit message"
git push origin --tags
git push --set-upstream origin name
git branch -u origin/foo - track remote branch
git remote -v - view list of remotes
git remote set-url origin - set remote
git branch -m newname - rename current branch

git push origin master -f - forced push

Rebase branch

git checkout feature/branch
git rebase master
git checkout master
git merge feature/branch // fast-forward here

Cleanup

git branch -D name - delete branch locally
git push origin --delete branchname or git push origin :branchname (:branchname should not exist locally then)git

git tag -d name - delete tag locally
git push origin :refs/tags/name - delete tag remotely

git reset --hard HEAD~1 - one commit back

git remote show origin (shows what is in origin and what is stale)
git remote prune origin (removes all local garbage from repo)
git branch -lvv (view list of branches with remotes and marks if remote gone)
git clean -df (remove all untracked files)
git checkout . (discard all the changes to tracked files)

Code snippet to investigate an object content without dances with debugger in C#

var investigated = ...; // assign your object here
System.IO.File.WriteAllText(
    @"D:\test.json",
    Newtonsoft.Json.JsonConvert.SerializeObject(
        investigated, 
        new Newtonsoft.Json.JsonSerializerSettings
        {
            Formatting = Newtonsoft.Json.Formatting.Indented,
            TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects
        }));

November 09, 2015

Rethrow exception and preserve stack trace in.net 4.5

ExceptionDispatchInfo.Capture(myException).Throw();