Skip to content

Instantly share code, notes, and snippets.

@otzoran
Last active December 30, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otzoran/65c07c997e2f4876f2de to your computer and use it in GitHub Desktop.
Save otzoran/65c07c997e2f4876f2de to your computer and use it in GitHub Desktop.
git memo

uploaded from otxe6530::git-memo

undo commit

git reset --soft HEAD^	    #and move from that commit to staging

git reset --hard HEAD^	    #and wipe changes, files aren't put in staging (reverted)

git reset --hard HEAD^^	    #revert to 2 commits back

Here's a comforting quote from Scott Chacon:

One of the topics that I didn't cover in depth in the Pro Git book is the reset command. Most of the reason for this, honestly, is that I never strongly understood the command beyond the handful of specific use cases that I needed it for. I knew what the command did, but not really how it was designed to work.

In Scott's blog, 2011

unstage file (undo git add)

git reset HEAD <file>

untrack file

git rm --cached <file>	# _not deleted from local filesys, only from git_

discard recent changes (revert file to last commit)

git checkout -- <file>

add forgoten file to the last commit or change the commit message

git add <file>
git commit --amend -m "text" #as if file was commited in last + replace commit txt

Add

add all txt files recursively

git add "*.txt"

add a remote repository

origin is a shorthand (like variable name) to the URL, "origin" is a convention git remote add origin https://github.com/....

show remote repositories:

git remote -v   

pushing to remote

    git push -u origin master 	# "-u origin" is for next time, we'll just type 'git push'

github password caching (https) enter once user + passwd

Explained in https://help.github.com/articles/set-up-git

  • The credential helper only works when you clone an HTTPS repository

!! DONT: undo (git reset etc) after you PUSH !!

  • Fast-Forward means
    merge branch to master, nothing changed on master since branch

understanding pull

  1. fetch = sync local repo with remote
    fetch updates "origin/master" - a branch! mirroring the remote master
  2. merge = perform
    git merge origin/master AUTO and IMMED after the 'pull'

create a remote branch

git checkout -b shopping_cart
git push origin shopping_cart		# _link local to remote and start tracking_

show remote branches

    git remote -v

    git remote show origin
  • VERY important: shows where repo came from etc.
    in the example below, we see this local repo is connected with bitbucket, state of local and remote branches...
    =============================================
    [18:03:08]ori@otxe6530[OstkInstal]
    $ git remote show origin 
    Warning: Permanently added the RSA host key for IP address '131.103.20.167' to the list of known hosts.
    Enter passphrase for key '/home/ori/.ssh/vubu10LTS.id_rsa.priv.pass_protected': 
  * remote origin
    Fetch URL: git@bitbucket.org:otzoran/ostkinstal.git
    Push  URL: git@bitbucket.org:otzoran/ostkinstal.git
    HEAD branch: master
    Remote branches:
  	master                           tracked
  	refs/remotes/origin/yokamina-s13 stale (use 'git remote prune' to remove)
  	yokamina                         tracked
    Local branches configured for 'git pull':
  	master   merges with remote master
  	yokamina merges with remote yokamina
    Local refs configured for 'git push':
  	master   pushes to master   (up to date)
  	yokamina pushes to yokamina (up to date)
  ==============================================
  • ? what does "tracked" means? other values seen:
    grizzly      new (next fetch will store in remotes/origin)
	refs/remotes/origin/yokamina-s13 stale (use 'git remote prune' to remove)
    yokamina                         tracked

delete a remote branch

  • del remote
	git push origin :shopping_cart
  • del local
	git branch -d shopping_cart

Now "stale" means the remote was deleted, local still exists if i try to
git push to this non-existent remote, git says
Everything up-to-date

Cleanup remote stale branches:

git remote prune origin
Pruning origin 
URL: https:....
 * [pruned] origin/shopping_cart

Remote Branch Names

example using Heroku deploys only master branch

    git push heroku-staging staging:master

Tagging

a tag is a reference to a commit - used mainly for Release Versioning
checkout code at commit:

    git checkout v0.1   

to push new tags:

    git push --tags
  • if not, tags remain local

Rebase

reason [?] "merge commits are polluting the history"

history & configuration

  • The awesome: shows the FULL history of repo, where is HEAD, tags, remotes and oneline comments in a graph
git log --all --graph --decorate --pretty=oneline --abbrev-commit

See full reply on (Stackoverflow)[http://stackoverflow.com/questions/7758113/how-to-git-log-the-entire-repository-and-not-just-the-branch-you-are-on] including how to add a git alias

  • log format options
  • git blame
  • exclude: line in .git/info/exclude can replace a line in .gitignore, in which case it's not visible
  • my ogitlog
alias ogitlog='git log --pretty=format:'\''%C(yellow)%h %Creset%ad %C(magenta)%an%Cgreen%d %Creset%s'\'' --date=iso'

push to an empty remote:

taken from: http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/

[remote]
	mkdir ori_test.git
	git init --bare
[local]	
	remote add origin ssh://lux@54.221.17.172/home/lux/ori_test.git
	git push -u origin master
  • note that the remote dir is in .git format, it doesnt extract the files after the push
  • need git clone to another dir [on remote] to use the files

git repo managers

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