GIT Cheat Sheet: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| (19 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Basic commands (local) = | |||
= Basic commands = | |||
== Creating == | == Creating == | ||
git init | git init | ||
== Adding | == Adding files == | ||
git add <filename> | git add <filename> | ||
or to commit all files in current directory: | |||
git add . | |||
== Committing changes == | == Committing changes == | ||
git commit | git commit -m <message> | ||
or | |||
git commit -m <message> FILE1 FILE2 FILE3 ... DIR1 DIR2 ... | |||
or to commit all that needs: | |||
git commit -m <message> -a | |||
== Seeing changes == | == Seeing changes == | ||
git log | git log | ||
== Tagging == | |||
Adding a tag | |||
git tag <tagname> -m "Comment about this tag" | |||
Listing tags with comments | |||
git tag -n | |||
== Seeing files inside repository == | |||
git ls-files | |||
git ls-tree HEAD | |||
== Branching == | |||
git branch | |||
git branch <NEW_BRANCH_NAME> | |||
git checkout <NEW_BRANCH_NAME> | |||
git commit -a | |||
git checkout master | |||
git merge <NEW_BRANCH_NAME> | |||
Diff between two branches | |||
git diff master..<NEW_BRANCH_NAME> | |||
= Remote commands = | |||
== Creating an empty project on a remote machine (DH) == | |||
For first import into a GIT server for example: | |||
ssh username@yourcheaphost.com | |||
mkdir -p ~/git/yourproject.git | |||
cd ~/git/yourproject.git | |||
git --bare init | |||
And then on the local machine: | |||
mkdir yourproject | |||
cd yourproject | |||
git init | |||
git remote add origin ssh://username@yourcheaphost.com/~/git/yourproject.git | |||
touch .gitignore | |||
git add . | |||
git commit -m "Initial Commit" | |||
git push origin master | |||
and add this to your .git/config in your project. | |||
[branch "master"] | |||
remote = origin | |||
merge = refs/heads/master | |||
== Push your developer commits to server == | |||
git push origin master | |||
== Get a copy of a project == | |||
git clone gitservername:proj1 proj1 | |||
== Update my local copy with the server's copy == | |||
git pull | |||
== Get server's copy from a new machine == | |||
git clone ssh://[<user@>]yourcheaphost.com/git/yourproject.git | |||
= Troubleshooting = | |||
== git “fatal: no matching remote head” == | |||
Cause: cannot fetch/clone remote empty GIT repo | |||
<pre> | |||
mkdir autobuildrequires | |||
cd autobuildrequires | |||
git init | |||
touch README | |||
git add README | |||
git commit -a -m "First commit." | |||
</pre> | |||
Link: http://rwmj.wordpress.com/2009/03/06/git-fatal-no-matching-remote-head/ | |||
= References = | = References = | ||
* Good guide: http://www.sourcemage.org/Git_Guide | * Good guide: http://www.sourcemage.org/Git_Guide | ||
* Another good one: http://toolmantim.com/article/2007/12/5/setting_up_a_new_rails_app_with_git | * Another good one: http://toolmantim.com/article/2007/12/5/setting_up_a_new_rails_app_with_git | ||
* Cmds vs. SVN: http://git.or.cz/course/svn.html | |||
* 10 Good Examples: http://www.kernel.org/pub/software/scm/git/docs/everyday.html | |||
* Good FAQ: http://git.or.cz/gitwiki/GitFaq | |||
* Good cheat sheet http://cheat.errtheblog.com/s/git | |||
Latest revision as of 19:03, 14 December 2010
Basic commands (local)
Creating
git init
Adding files
git add <filename>
or to commit all files in current directory:
git add .
Committing changes
git commit -m <message>
or
git commit -m <message> FILE1 FILE2 FILE3 ... DIR1 DIR2 ...
or to commit all that needs:
git commit -m <message> -a
Seeing changes
git log
Tagging
Adding a tag
git tag <tagname> -m "Comment about this tag"
Listing tags with comments
git tag -n
Seeing files inside repository
git ls-files git ls-tree HEAD
Branching
git branch git branch <NEW_BRANCH_NAME> git checkout <NEW_BRANCH_NAME> git commit -a git checkout master git merge <NEW_BRANCH_NAME>
Diff between two branches
git diff master..<NEW_BRANCH_NAME>
Remote commands
Creating an empty project on a remote machine (DH)
For first import into a GIT server for example:
ssh username@yourcheaphost.com mkdir -p ~/git/yourproject.git cd ~/git/yourproject.git git --bare init
And then on the local machine:
mkdir yourproject cd yourproject git init git remote add origin ssh://username@yourcheaphost.com/~/git/yourproject.git touch .gitignore git add . git commit -m "Initial Commit" git push origin master
and add this to your .git/config in your project.
[branch "master"] remote = origin merge = refs/heads/master
Push your developer commits to server
git push origin master
Get a copy of a project
git clone gitservername:proj1 proj1
Update my local copy with the server's copy
git pull
Get server's copy from a new machine
git clone ssh://[<user@>]yourcheaphost.com/git/yourproject.git
Troubleshooting
git “fatal: no matching remote head”
Cause: cannot fetch/clone remote empty GIT repo
mkdir autobuildrequires cd autobuildrequires git init touch README git add README git commit -a -m "First commit."
Link: http://rwmj.wordpress.com/2009/03/06/git-fatal-no-matching-remote-head/
References
- Good guide: http://www.sourcemage.org/Git_Guide
- Another good one: http://toolmantim.com/article/2007/12/5/setting_up_a_new_rails_app_with_git
- Cmds vs. SVN: http://git.or.cz/course/svn.html
- 10 Good Examples: http://www.kernel.org/pub/software/scm/git/docs/everyday.html
- Good FAQ: http://git.or.cz/gitwiki/GitFaq
- Good cheat sheet http://cheat.errtheblog.com/s/git