User Tools

Site Tools


scm:git:commands

Git setup

Username

First you need to tell git your name, so that it can properly label the commits you make.

git config --global user.name "Your Name Here"
# Sets the default name for git to use when you commit

Email

Git saves your email address into the commits you make.

git config --global user.email "your_email@youremail.com"
# Sets the default email for git to use when you commit

Git Commands

Take a look at following resources for more tips.

Create a project and add it to a Git repository

Example to upload to GitHub:

mkdir Project-Name
cd Project-Name
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:my_name/Project-Name.git
git push origin master

Add an existing project to a Git repository

Add an existing project to GitHub:

cd existing_git_repo
git remote add origin git@github.com:niwo/MySQL-Maintenance-Buddy.git
git push origin master

Create a clone of an remote git repository

Example:

git clone git://github.com/niwo/named-admin.git
If you are behind a proxy/firewall and have problem connecting trough the git port, use http:// instead.

Cloning and Creating a Patch

git clone git://github.com/git/hello-world.git
cd hello-world
(edit files)
git add (files)
git commit -m 'Explain what I changed'
git format-patch origin/master

Creating and Commiting

cd (project-directory)
git init
(add some files)
git add .
git commit -m 'Initial commit'

Switch to another remote branch

Similar to switching a svn branch with the switch command, with git a new local branch has to be created first in order to be able to checkout a different remote (in this example called origin) branch:

git branch test
git checkout origin test
/srv/wiki.niwos.com/data/pages/scm/git/commands.txt · Last modified: 2012/12/11 17:45 by niwo