Notes‎ > ‎


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.

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]
//git remote add origin ssh://[user]
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]
git svn clone -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

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}

git remote show origin

[tips & tricks]
git config --global alias.last 'log -1 HEAD'
git config --global checkout
git config --global branch
git config --global commit
git config --global status
git config --global "James Nguyen"
git config --global "james [dot] nguyen [at] gmail [dot] com"

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:
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

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.