Skip to content

Instantly share code, notes, and snippets.

@tareiking
Last active September 28, 2015 18:40
Show Gist options
  • Save tareiking/d1e39fd4ddc8bdb2effd to your computer and use it in GitHub Desktop.
Save tareiking/d1e39fd4ddc8bdb2effd to your computer and use it in GitHub Desktop.
CodeSchool Git Real notes

Gitreal notes

Favorites notes

  • Git aliases: Extended version here : https://git.wiki.kernel.org/index.php/Aliases
  • git push origin :branchname : remove a remote branch
  • git rebase : Tidy commit history. Remove merge commits
  • git prune : Clean up stale local branches when compared to remote

Continued learning

Basics

Tips: Origin/master is actually a branch that merges automatically with git pull

git diff --staged : diff on staging area git reset --soft HEAD^ : reset changes to 1 commit before HEAD git reset --soft HEAD^^ : reset changes to 2 commits before HEAD

git remote add <name> <address> : add a remote

git push -u origin master : push changes and set upstream git checkout -b admin : create, checkout branch with name 'admin'

Remotes

HINT: Create a branch and send to remote if your using it more than a day

git branch -r : list all remote branches

git remote show origin : show origin branches git branch -r : lists all remote branches git remote prune origin : remove any stale local branches

git push origin staging:master : *** pushes all changes in local 'staging' branch to the remote 'master' branch ***

```git push origin :weasel`` : delete a remote branch named 'weasel'

git tag -a v1.3.1 -m "Tagged to release 1.3.1" : Create a tag with a message

Rebase

Removes merge commit messages Applies changes specified changes above the existing timeline Use git rebase and git rebase --continue in merge conflicts

Logs

git log --oneline : shows you each commit on oneline git log --oneline --graph : shows you a graph git log -p : shows all file changes in a similar fashion to git diff

Date Ranges

git log --until=1.minute.ago git log --since=1.day.ago git log --since=1.hour.ago git log --since=1.month.ago --until=2.weeks.ago git log --since=2000-01-01 --until=2012-12-21

Diff

git diff HEAD^ : parent of latest commit git diff HEAD^^ : grandparent of latest commit git diff HEAD~5 : five commits ago git diff HEAD^..HEAD : second most recent commit vs. most recent commit git diff 321232..32123 : compare two SHA

Blame

git blame <filename> --date short : shows line by line who made file changes and when

Config

.git/info/exclude : store local files without including in the repo git rm --cached <filename> : removes tracking, but not the local file. combine with .gitignore and then commit

Alias

We can setup aliases on the git global level to make life easier (and without using bash aliases)

git config --global alias.<aliasname> \ <command to alias> example: git config --global alias.mylog \ "log --graph --decorate --pretty=online --abbrev-commit --all"

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