To Start with Git, we need to either create a new project, or “clone” a project from a URL.
Once you have a project, you edit files in that dir to make changes, then you need to “add” to a staging area, then “commit”. (these are done to your local repository.)
To get update from a server, or put your changes to a server , you need to pull or push.
First, you need to setup a default name and email. Else, git won't let you commit.
Everytime you commit, your user name and email is in part of the commit info. This allows git to show who did what, when working in a team. That's why user name and email are required. (you can use random name and email if you want)
# set up default name and email git config --global user.name "My Name" git config --global user.email "example@example.com" |
the above will create a file at ~/.gitconfig. You can run these commands again to change. (you can also edit the file directly.)
Important: when using git, you should always cd the directory first. This is in contrast to traditional unix commands, where you can simply give the directory's full path.
Example:
# cd to the dir containing your code cd my_project # initialize. This creates a .git dir. git init # add all files to “staging area” git add . # commit to local repository. git commit -m"my first commit" |
Git will create a dir named .git in the same dir. This dir is used by git for all its info, including its database.
Note: as of 2012, Adding 20k files takes about 6 minutes. Commiting 20k files takes 6 minutes.
Clone a projet means making a copy.
cd to a directory where you want the new project dir to be, then:
git clone source_path_or_url |
Example:
git clone git://repo path/ # get a copy of the js jquery source code
git clone https://github.com/jquery/jquery.git
|
git clone url_or_path → creates a dir in the current dir with the remote repo's content. The newly created dir will have the same name as project name of the remote repository at url_or_path. If a non-empty directory of the same name already exist, git will complain