Nov 162012
 

Q: How often should I checkin code into github?
A: More often is better than less often, if you write a lot of code, do it at least 2-4 times a day.

Q: Should I branch/fork?
A: branching and forking is there to help you better organize your code by feature. If you are working on an open source project, you will need to fork it first so that you have access to checkin code into it. After you forked a project, you may want to create branches for different features that you will be working on. If you are part of one organization where you have access to the repo, you may want to forgo the forking and go straight to branching. This is a decision that each group needs to make.

Q: Can I work from master?
A: Yes you can, but you probably should not! Think of your master branch as a golden copy of your code. Merge to it after you thoroughly tested your new features or bug fixes.

Q: What if command line scares me?
A: Use GUI tools built just for you!  There are lots of them out there, my favorite one is: http://mac.github.com/

Documentation

While looking up some documentation for git, I came across this awesome cheatsheet:
http://ndpsoftware.com/git-cheatsheet.html

Try clicking on it!

You may be aware of github documentation, but do visit git docs once in a while as well to get very clear and detail answers to all your git questions:
http://git-scm.com/doc

-eglute

 Posted by at 11:39 pm
Nov 162012
 

If you are currently working on a project that you would like to check into github, it may not be very obvious at first. This step by step tutorial assumes that you already setup your github account.  If you have not, follow these instructions first: https://help.github.com/articles/set-up-git. Once your github is setup, create a new repo trough UI: https://github.com/new

In this example, I will use repo “testRepo”, just to keep it simple!

Now, on your command line, go to your existing project. For the sake of this tutorial, the names of existing project and git repo are the same, but they do not have to be.

My current project has 2 files:

egle@ubuntu:~/testRepo$ ls -la
total 16
drwxrwxr-x  2 egle egle 4096 Nov 16 19:41 .
drwxr-xr-x 25 egle egle 4096 Nov 16 19:40 ..
-rw-rw-r--  1 egle egle   14 Nov 16 19:41 file1.txt
-rw-rw-r--  1 egle egle   15 Nov 16 19:41 file2.txt

To turn this directory into a git repository, I need to initialize it:

egle@ubuntu:~/testRepo$ git init
Initialized empty Git repository in /home/egle/testRepo/.git/

This creates a local git repository on your machine. That’s right, you can version files locally without ever needing to connect to github or other git server! Note that currently your new git repo contains no files.

Add all the files to the repository:

egle@ubuntu:~/testRepo$ git add .

Once the files are added, they need to be committed:

egle@ubuntu:~/testRepo$ git commit -m "first commit"
[master (root-commit) b9c1002] first commit
Committer: Egle <egle@ubuntu.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author
2 files changed, 2 insertions(+)
create mode 100644 file1.txt
create mode 100644 file2.txt

In this case, I have not setup my git settings, so will need to fix that later. The important part here is that files got committed to the local repo.  However, local repositories are a little hard to share. Lets add a remote repository, named origin, and push files to it:

egle@ubuntu:~/testRepo$ git remote add origin https://github.com/eglute/testRepo.git
egle@ubuntu:~/testRepo$ git push -u origin master
Username for 'https://github.com': eglute
Password for 'https://eglute@github.com': 
To https://github.com/eglute/testRepo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

Now your current project is in github, ready for pulls, pushes, merges, branches, and forks!

-eglute

 

 Posted by at 11:02 pm
Nov 162012
 

It seems like everyone is using github these days, and it is easy to fork and branch trough it’s UI. But what if you are just starting with using git?

I will reveal a few not so hidden secrets of git. First, github is based on git, so if you just been reading github documentation, you are missing out on a lot of great documentation that can be found here: http://git-scm.com/doc.

Second, when you are using github, you are really working with two repositories, not one. The first one is on your local machine, set up to point to the second, remote repo.

Here are a few tips on how to configure your local repo:

You will want to start with git config tool to configure your git profile. git config will setup your identity and some preferences.

Start with setting your name:

egle@ubuntu:~/testRepo$ git config --global user.name "Any Stacker"
 egle@ubuntu:~/testRepo$ cat ~/.gitconfig
 [user]
 name = Any Stacker

A few more settings:

egle@ubuntu:~/testRepo$ git config --global merge.tool vimdiff
 egle@ubuntu:~/testRepo$ cat ~/.gitconfig
 [user]
 name = Any Stacker
 [merge]
 tool = vimdiff
 egle@ubuntu:~/testRepo$ git config --global core.editor vi
 egle@ubuntu:~/testRepo$ git config --list
 user.name=Any Stacker
 merge.tool=vimdiff
 core.editor=vi
 core.repositoryformatversion=0
 core.filemode=true
 core.bare=false
 core.logallrefupdates=true
 remote.origin.url=https://github.com/eglute/testRepo.git
 remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
 branch.master.remote=origin
 branch.master.merge=refs/heads/master
 egle@ubuntu:~/testRepo$

Don’t be a git, check in your code often!

-eglute

 Posted by at 10:47 pm