GIT
Some GIT commands I use and wanted to note for my own reference in case I don’t use it anymore for some time and can’t remember ;-)
Submodules
Adding a submodule to a project
$ git submodule add <insert.repo.uri> destination/pathInitialize submodules in a fresh checkout
$ git submodule init
$ git submodule updateFetch changes from submodule
Doing it for all existing submodules
$ git submodule foreach git pullForking
Adding upstream to your fork
$ git checkout master
$ git remote add upstream <insert.repo.uri>
$ git fetch upstream
$ git rebase upstream/masterHosting git repositories
Here are some projects which help you to self host your environment
Initialize local git repository and create origin master
Go to the root directory you want for this repo and execute following commands
local$ git initlocal$ ssh server
server$ cd /path/to/git/root
server$ mkdir newrepo.git && cd newrepo.git
server$ git --bare init
server$ exitlocal$ git remote add origin ssh://server/path/to/repo.git
local$ git push origin masterclone a git for local changes that can be pushed again to origin master
local$ git clone ssh://server/path/to/repo.gitRemove files from git
In this example it’s the .DS_Store file created automatically on a mac
local$ find . -depth -name '.DS_Store' -exec git rm --cached '{}' \; -printAdd them to the ignore list
Execute this command in the root of the git directory
local$ echo ".DS_Store" >> .gitignore
local$ git add .gitignore
local$ git commit -m ".DS_Store removed and ignored"Ignores for mac client
.DS_Store
._*Ignores for working with latex
*.aux
*.dvi
*.ilg
*.ind
*.log
*.lol
*.out
*.toc
*.ps
*.glo
*.nlo
*.ilg
*.nls
*.bbl
*.blgUpload to remote master
If you have not added the origin yet, do this first
local$ git remote add origin ssh://server/path/to/repo.gitTo push the files
local$ git push origin masterStay in sync with remote repository
local$ git pull origin masteradd changes
Add all changed / new files to the next commit
local$ git add .local$ git stage .local$ git add -icreate local branch, do your work and merge it back to local master
New Branch from whatever branch you are in
local$ git branch task1Do your changes and commit as usual. You can even switch branches in between.
Switch to the master (or whatever branch you branched from)
local$ git checkout masterMerge your temporary branch into master
local$ git merge task1Delete your temporary branch
local$ git branch -D task1Show me all branches
local$ git branch -aSwitch branch
local$ git checkout masterShow me changes since last commit
To see the actual code / cleartext:
local$ git diff --cachedlocal$ git diff --stagedMore details and a nice graphic can be seen at http://365git.tumblr.com/post/474079664/whats-the-difference-part-1
Save dirty code and revert back to HEAD
local$ git stash --keep-indexTo restore into the dirty code (merging it into your current state)
local$ git stash applyDetailed description of the stash command can be found at http://www.kernel.org/pub/software/scm/git/docs/git-stash.html
Links
- http://help.github.com/removing-sensitive-data/
- http://www.uhlme.ch/artikel.php?artikel=git
- http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
- https://gist.github.com/569530
- http://www.kernel.org/pub/software/scm/git/docs/everyday.html
- http://365git.tumblr.com/post/474079664/whats-the-difference-part-1
- http://linux.yyz.us/git-howto.html
- http://cheat.errtheblog.com/s/git
- http://progit.org/book/