Patricio Treviño

Patricio Treviño

Husband . Father . Developer
8total entries in git

Rebase a pull request

There is nothing more daunting than rebasing your first pull request. I still remember the day I was asked to do this and, honestly, I can't recall how I pulled it off, but I did... of course this was years ago when there was no Update branch button in Github (which by the way, does a merge commit which I personally dislike). So I'm gonna save you some time and a lot of trouble with this mini guide.

Stash all changes in a git repository

Syntax

# stash everything (tracked, untracked, ignored)
git stash --all
# stash everything, (tracked and untracked, but not ignored)
git stash [save -u | --include-untracked]
view raw syntax.text hosted with ❤ by GitHub

Rename a git branch

There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton

As Phil Karlton says, naming things has, is, and will always be hard. This is especially true when you are the new guy in the office and you are still trying to memorize the thousands and thousands of code standards/conventions the new team has.

Fortunately for the new guy, almost everything has a fix and when it comes down to branch naming conventions it is as easy as following the steps described in this guide.

Delete a local and remote git branch using the terminal

Syntax

git branch <[-dr | --delete --remotes]> <remote>/<branch>
view raw syntax.text hosted with ❤ by GitHub

Option Description
remote The remote to be used.
branch The remote branch to be deleted.

Note: valid options are:
-dr, is a synonym of --delete --remotes
--delete, deletes the local branch with no pending merges.
--remotes, tells git to delete the remote tracking branch too.

Delete a local git branch using the terminal

Syntax

git branch <[-D | -d | --delete]> <branch>
view raw syntax.text hosted with ❤ by GitHub

Option Description
option The delete option to be used.
branch The local branch to be deleted.

Note: valid options are:
-D, forces the deletion of the local branch even if there are pending merges.
-d, is a synonym of --delete.
--delete, deletes the local branch with no pending merges.

Delete a remote git branch using the terminal

Syntax

git push <remote> --delete <branch>
view raw syntax.text hosted with ❤ by GitHub

Option Description
remote The remote to be used.
branch The remote branch to be deleted.

Prunes the repository from deleted remote branches using the terminal

Syntax

git fetch [remote] [-p | --prune]
view raw syntax.text hosted with ❤ by GitHub

Option Description
remote The remote to be used (defaults to origin).

Get the delta between two git branches

Syntax

git diff [options] <commit>[..<commit>] [--] [<path>...]
view raw syntax.text hosted with ❤ by GitHub

Option Description
options The differen options that can be used to report the differences
commit An arbitrary commit/branch to be compared.
commit The second commit/branch to be compared, if omitted then HEAD (of the current branch) is used.
path... If path is specified, then the comparison happens at the file level instead of commit/branch level.

Note: common options are
--minimal, spend extra time to make sure the smallest possible diff is produced.
--summary, output a condensed summary of extended header information such as creations, renames and mode changes.
--name-only, show only names of changed files.
--name-status, show only names and status of changed files.
--diff-filter, select only files that are:
Added (A) Copied (C) Deleted (D) Modified (M) Renamed (R) Changed (T) Unmerged (U) Unknown (X) airing Broken (B)