Sunday, September 20, 2009

Few commands in Git source control system

I always prefer writing commands rather than using the tool and be a handicap. In Windows Explorer, right-click on the working directory you want and choose “Gui Bash Here”. Then enter a command like this:

To clone a repository from remote repository, you will have to type

git clone git@github.com:firstnamelastname/yourrepo.git

git clone repoURL

Git might prompt you about an SSH key, the first time you do this with github (or any other new server). Answer “yes”.

It’s worth pointing out here, if you didn’t already understand from the various Git web sites, that Git is a distributed source control system. It will pull down the whole project history, so you can browse history and even commit changes without online access. Thus Git works very well if you have an intermittent or poor network connection.

Few commands:

As with all source control, work in the directory where you use source control. Do not copy files back and forth between here and some other working directory, that is a path to endless merge and update problems.

Once you have checked out the software, here is a summary of your work flow. For more details, please read the copies Git documentation online. I suggest reading both the official Git material, as well as other sites and articles about Git.

Getting Changes

Get changes from others with “git pull” (or using the GUI). By default this will pull from the repo from which you cloned, so if you cloned the upstream repo, that will get other peoples’ changes.

If you cloned from your own Git hub repo, you’ll need to use something like this:

git remote add upstream git@github.com:firstnamelastname/yourrepo.git

git pull yourname upstream

Sending Changes

Commit your changes locally with “git commit” (or using the GUI). Remember that Git generally wants you to explicitly say which files’ changes to include (”git add”), so make sure you read and understand enough about Git to do this properly; it is only a few commands or clicks in the GUI. The usual caveat applies, to only commit actual source files, not generated files or temp files.

Push your changes up to your GitHub repository with “git push”. This step will make it so others on your project can see your changes. Do this at least once per day, and ideally more often as you collaborate. Assuming that you cloned from the upstream repo, you’ll need to set up a reference to your own Git hub repo (the one you can push to), with something like this:

git remote add name git@github.com:firstnamelastname/yourrepo.git

As usual, use reasonable names and relevant URLs, not my sample names and URLs. Once you’ve added the remote reference, pushing is easy:

git push name master

When you have a set of changes (one or more commits) that you think are ready to go in to the main-line of the project, use Git hub to issue a “pull request”.A key thing to understand about Git is that it makes branching extremely easy and fast, so that very convenient to use branches.

No comments:

Post a Comment