1. git init
Create a new repo with exsiting project.
2. git diff
This command compares what's in your working directory with what's in your staging area. The result tells what changes have not been staged.
3. git diff --cached
Shows what you've stage that will go into your next commit. In Git v1.6 or later, you can use git diff --staged.
4. git comit -a -m 'comment'
skip staging area. You do not need run git add before you commit.
5. git rm
Reimoves the file from your working directory and you don't see it as an untracked file next time.
6. git rm --cached
Remove the file from Git but keep it on your hard disk.
7. git mv file_a file_b
8. git log -p -2
This example shows last two commit log. -p shows diff introduced in each commit.
9. git log --pretyy=format:"%h %s" --graph
shows branch and merge history. More options:
Option Description of Output
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author e-mail
%ad Author date (format respects the –date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
10. git commit --amend
You can redo your last commit. This can be useful when you forgot to git add some files or you want to edit your commit message.
11. git reset HEAD
Change file to unstage.
12. git checkout -- filename
This discards your current changes. It looks like when you last committed.
13. git remote add shortname remote_repo
This command adds a remote repo. git remote -v shows your current remote repo.
14. git fetch shortname
This fetches all information you don't have in your repo but in shortname. After this, you have all refs to all branches from that remote. you can run git merge shortname/master to merge it into your master branch.
Notify git fetch pulls all new commit to your working directory but does not automatically merge it.
15. git pull
This fetches data and merges.
16. git push [remote-name] [branch-name]
E.g., "git push origin master" pushes your master branch to origin repo.
17. To be continued...