Tuesday, November 9, 2010

GIT cheatsheet

I'm tired of zipping my source code up and unzipping it on another machine. It's problematic and ineffective.

Here is my git cheatsheet for working on several machines at once.

Pre-requirements
git

Configure git
So, let's say your main development machine is your laptop:

[laptop:anywhere]>git config --global user.name "Matthew Vincent"
[laptop:anywhere]>git config --global user.email matt.vincent@jax.org


Initialize git Project on the laptop

[laptop:projectdir]> git init
Initialized empty Git repository in [laptop:projectdir]
[laptop:projectdir]> git add .
[laptop:projectdir]> git commit -m "Initial import of project"
[master (root-commit) 62e08f7] Initial import of project
2688 files changed, 819887 insertions(+), 0 deletions(-)
create mode 100644 file1
create mode 100644 file2
...
create mode 100755 fileX
[laptop:projectdir]> git remote add [projectname] [laptop:projectdir]


Configure git (again)
Let's now say you also work on a server

[remote:anywhere]>git config --global user.name "Matthew Vincent"
[remote:anywhere]>git config --global user.email matt.vincent@jax.org


So now, we want to pull from the laptop

[remote:projectdir]> git init
[remote:projectdir]> git remote add [projectname] [userid]@[laptop]:[laptop:projectdir]
[remote:projectdir]> git pull [projectname] [branchname] # i.e. master


And we'll branch

[remote:projectdir]> git branch [branchname]
[remote:projectdir]> git checkout [branchname]
Switched to branch "[branchname]"


And make some changes...

And commit and push back to laptop

[remote:projectdir]> git commit -a -m "commit message"
[remote:projectdir]> git push [projectname] [branchname]


Back to laptop land
Let's merge

[laptop:projectdir]> git merge [branchname]
Updating 62e08f7..6a3fbaf
Fast-forward
file1 | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)


Optionally cleanup if wanted...

[laptop:projectdir]> git branch -D [branchname]