Git is a distributed version control system.
The code go through four stages:
Here's a synopsis of the transitions and related commands:
The most common commands follows.
git config --global user.name "Davis Fiore"
git config --global user.email [email protected]
git config --list
git init
git add *
git diff
Specify a path if you intend to limit the scope.
git diff HEAD
git diff --cached HEAD or git diff --cached
The option --staged has the same effect.
git diff branch1..branch2
git diff hash1 hash2
git log branch1..branch2
git commit -a -m 'My comment'
git add myfile.txt git commit -m 'My comment'
If you created or changed a file and you didn't add it to the staging area, it will be ignored during the commit.
rm myfile.txt git rm myfile.txt
git log
git log --oneline --decorate --graph --all
git show
git show commit_hashcode
git reflog
git blame filename
git commit --amend
Use --no-edit if you don't want to modify the comment.
git clone respotiory_url
git fetch repository_name
git pull repository_url
The local copy of the remote repository is update first, with a fetch. Then a merge is perfomed to update the local repository from the copy of the remote repository. The option --rebase is used to perform a rebase instead of a merge.
git push
The first time you push, use the option -u to link your local repository to the repome one.
git tag tag_name
The tag create is lightweight (just a reference). Use the option -a for an annotated tag (actual object).
git show tag tag_name
git tag -l
git tag -l "2.0*"
git diff tag1 tag2
git tag tag_name --delete
git push origin tag_name
git push origin --tags
git push origin --follow-tags
It's a good practice to push only annotated tags.
git push origin :tag_name
git checkout -b branch_name
git checkout -b branch_name source_branch_name
git checkout branch_name
git checkout path
git checkout -- file_name
git branch
git branch branch_name
git branch -d branch_name
git push origin --delete branch_name
git merge branch_name
When the merge fails because of a conflict, you need to fix the conflicts and then commit. But merge commits automatically when there are no conflicts.
Also, note that branch_name merge with the local copy of the branch, whereas "origin/branch_name" merge with the remote version.
git mergetool
git rebase other_branch
git cherry-pick commit_hashcode
git revert commit_hash Or git revert HEAD
Note that HEAD is the last commit in the current branch.
git reset --hard commit_hash
git reset --soft commit_hash
git reset commit_hash
git reset --hard HEAD
git reset HEAD file_name
Same behavior if HEAD is omitted. Without filename, it applies to all the files.
In alternative:
git rm --cached file_name
This makes a file untracked and it's the opposite of "git add". A file needs to be untracked in order to be ignored (see .gitignore)
git status
git stash
This is used when you need to temporarily switch to a different branch.
Use the option --index option, if you want to consider the stagin area as well.
git stash apply
git stash list
git stash show [email protected]{2}
git stash -u
git stash drop
git stash pop
git stash clear
git tag -l
git checkout tags/tag_name
git push --tags
git push --set-upstream origin my_branch
git remote add origin https://[email protected]/myproject/mygit.git
git remote -v
git clean -df .
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.