Skip to content

Instantly share code, notes, and snippets.

@fcmendoza
Last active April 18, 2022 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcmendoza/5284c805cd1b45f2ff34cbda71bef7d4 to your computer and use it in GitHub Desktop.
Save fcmendoza/5284c805cd1b45f2ff34cbda71bef7d4 to your computer and use it in GitHub Desktop.
Geet Get Git
# See comments for examples
@fcmendoza
Copy link
Author

fcmendoza commented May 17, 2019

Create Branch

cd c:\Git\credo
git checkout develop 
git pull
git checkout -b mep-2608 
git push origin mep-2608
git branch --set-upstream-to=origin/mep-2608 mep-2608
git log -11

For microservices branch is off master

cd /to/brach/dir
git checkout master
git pull
git checkout -b fma/MITB-130-xray
git push origin fma/MITB-130-xray
git branch --set-upstream-to=origin/fma/MITB-130-xray fma/MITB-130-xray
git log -11

@fcmendoza
Copy link
Author

fcmendoza commented Sep 30, 2019

Get specific commit

# this is a bash function
revert-to() {  # $1 is the commit hash
	git reset $1 && git checkout . && git super-clean && git log -11
}

Overwrite local with remote

# this is a bash function
bitbucket-wins() { # $1 is the branch name: e.g.: fma/CPAC-183-new-petitions
	git fetch --all && git reset --hard origin/$1
}

# usage: bitbucket-wins branch-name

@fcmendoza
Copy link
Author

fcmendoza commented Sep 30, 2019

Git Aliases

Put the following in ~/.gitconfig

[alias]
	nuke-last-commit = reset --hard HEAD~1
	superclean = clean -fdx
	super-clean = clean -fdx

Git log format

[log]
	date = short
[format]
	pretty = tformat:"%C(yellow)%h  %C(cyan)%ad%Creset%x09%an%x09%Cgreen%s%Creset" 

That will give you something like this:

image

@fcmendoza
Copy link
Author

Compare specific file between two branches

git difftool master..feature/test-branch -- src/Core/DataAccess/Repositories/Dynamo/DynamoRepository.cs

Viewing (1/1): 'src/Core/DataAccess/Repositories/Dynamo/DynamoRepository.cs'
Launch 'bcomp' [Y/n]? y

In ~/.gitconfig I have BeyondCompare as the diff tool configured

[diff]
  tool = bcomp
[difftool]
  prompt = true
[difftool "bcomp"]
  trustExitCode = true
  cmd = "/c/Users/John/Downloads/bc4/bcomp" \"$LOCAL\" \"$REMOTE\"

Source: https://devconnected.com/how-to-compare-two-git-branches/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment