Published Feb 28, 2012
After Hosting Your Own Git Repositories I have been thinking of continuing on topics about Git, although I am not an expert. Please point out and comments if you have a better idea or anything to improve. Thanks!
Setting up your display name and email address show in Git commits.
$ git config --global user.name "Your Name" $ git config --global user.email "[email protected]"
You have to do this once and Git will remember you every time you commit your works.
git clone you can simply get a copy of the project you want to work on.
$ git clone [email protected]:test.git Cloning into test... [email protected]'s password: remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done. $ cd test $ ls -a . .. .git README index.html
git add you are able to add files to the project’s staging area.
$ echo "<?php phpinfo();" > info.php $ ls -a . .. .git README index.html info.php $ git status -s ?? info.php $ git add info.php $ git status -s A info.php $ git diff HEAD diff --git a/info.php b/info.php new file mode 100644 index 0000000..c4837a3 --- /dev/null +++ b/info.php @@ -0,0 +1 @@ +<?php phpinfo();
After adding files into staging area, you can now use
git commit to create snapshot of the changes.
$ git commit -a -m 'add info file' [master a591ab6] add info file 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 info.php
Commits are done locally before a
git push command is given.
Power of the collaboration system, with
git pull your local codes are to be sync’ed with other collaborators.
$ git pull [email protected]'s password: remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From server.com:test a591ab6..5781fe7 master -> origin/master Updating a591ab6..5781fe7 Fast-forward info.php | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
git pull combines
git fetch with
git merge commands, where will fetch the updates and merge into your local codes.