Git

This reference will create a remote bare git repository so that a remote origin repo can be created and pushed to the master. We then can clone from any host, make changes and push back upstream. I’ve been using branches and tags and so there are more and more notes nicely scattered for quick reference so I don’t have to dig through pages and pages of manuals. Honestly I don’t think any one project will use ALL of git’s features except maybe the kernel project.

Why git?

* Branching is fast and easy.

* Offline work is supported; local commits can be submitted later.

* Git commits are atomic and project-wide, not per-file as in CVS.

* Every working tree in Git contains a repository with a full project history.

* No Git repository is inherently more important than any other.

[remote]

ssh bluecentre.net

mkdir -p var/git/home.git

cd var/git/home.git

git --bare init

cd ..

find home.git -type d -exec chmod 2750 {} \; && find home.git -type f -exec chmod 640 {} \;

sudo chgrp -R apache home.git

#cd /var/git

#ln -s $HOME/var/git/home.git /var/git

[push existing repo to remote]

cd /repo

git init

git remote add --track origin ssh://[user]@bluecentre.net/var/git/repo.git

//git remote add origin ssh://[user]@bluecentre.net/var/git/repo.git

touch README

git commit -am 'initial commit'

//git config branch.master.remote origin

//git config branch.master.merge refs/heads/master

git push origin master

[clones git/svn]

git clone ssh://[user]@bluecentre.net/var/git/home.git

git svn clone http://pidgin-lastfm.googlecode.com/svn -T trunk -b branches -t tags

[create/track/delete remote branch]

git push origin origin:refs/heads/new_branch

git checkout --track -b new_branch origin/new_branch

git push origin :new_branch

[tags]

git tag <= display list of tags

git tag v1.1 -m 'last working new feature...'

git push --tags

git reset --hard v1.1

[squash commits]

git commit --amend

or between branches

git rebase -i [origin/]master

[reset changes from hash]

git whatchanged

git reset <hash> path/to/file

git checkout path/to/file

[revert last commit]

git reset HEAD@{1}

[info]

git remote show origin

[tips & tricks]

git config --global alias.last 'log -1 HEAD'

git config --global alias.co checkout

git config --global alias.br branch

git config --global alias.ci commit

git config --global alias.st status

git config --global user.name "James Nguyen"

git config --global user.email "james [dot] nguyen [at] gmail [dot] com"

[colour]

git has supported a “–color” argument for several commands, like diff and log. however, there wasn’t an easy way to make colorized output the *default* nor could you change the colors until v1.5 and above. you can turn on color by default and also change the colors. put the following in your “.git/config” file:

[color]

branch = auto

diff = auto

status = auto

[color "branch"]

current = yellow reverse

local = yellow

remote = green

[color "diff"]

meta = yellow bold

frag = magenta bold

old = red bold

new = green bold

[color "status"]

added = yellow

changed = green

untracked = cyan

or enter the following commands:

git config color.branch auto

git config color.diff auto

git config color.status auto

[concepts]

git pull == git fetch origin + merge origin back into your active branch. All history is preserved; [the] pull command can be seen as "merge commit" in the history.

git rebase origin == git format-patch old origin + throw away your active branch and replace it with a copy of the new origin + apply all the patches git format-patch generated.

[references]

http://progit.org/book/

http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html

http://www.kernel.org/pub/software/scm/git/docs/everyday.html

http://www-cs-students.stanford.edu/~blynn/gitmagic/book.html

http://robots.thoughtbot.com/post/165641717/rebase-like-a-boss

http://cheat.errtheblog.com/s/git

http://code.google.com/p/support/wiki/ImportingFromGit

http://stackoverflow.com/questions/661018/pushing-an-existing-git-repository-to-svn

http://flavio.castelli.name/howto_use_git_with_svn

https://csswizardry.com/2017/05/little-things-i-like-to-do-with-git