Skip to content

Working with git

zenbones edited this page Mar 14, 2011 · 1 revision

Working With Git

All operations in Git are local, meaning that Git's repository and all changes are kept in your local file system. When you check-in, you're doing so locally. When you switch branches, that's local. When you merge, it's local. In order to make those changes visible in the remote repository, or to synchronize changes from the remote repository, you must use the git push or git pull commands, respectively. The trunk code line in Git, by convention, is a branch called 'master'. The remote repository, again by convention, is known as 'origin'. The following is a brief list of useful git commands, and their results.

Creating a brand new clone of the remote repository

git clone ssh://<user name>@<git host>/<git repository>

This will grab all branches available in the remote repository and create a local copy of it all, to which you can commit your changes.

Changing local branches

git checkout <branch name>

For instance, switching to the trunk can be accomplished with git checkout master.

Setting up a new branch to track a remote branch

git pull origin <local branch name>:<remote branch name>

If you don't have a local copy of a new remote branch, this will solve that problem.

Adding new files to the current change list, so that they'll be part of your next commit

git add <file spec>

Given a directory name, add will operate recursively on the directory structure, so to add all new files recursively, from the current directory, you would use...

git add .

You can limit this using wild cards, as in git add ./*.xml to add all new .xml files recursively, form the current directory.

Removing files so that they'll be deleted in your local repository as well, upon your next commit

git rm <file spec>

Committing your changes to your local repository

git commit

If you would like to avoid specifically adding new files with git add, and removing unwanted files with git rm, then you can simply use...

git commit -a

...which will notice new files and add them, and will notice deleted files and remove them.

Pulling remote changes into your local repository

git pull

Pushing locally committed changes to the remote repository

git push

Clone this wiki locally