git config --global user.name "Tib Onu"
git config --global user.email "tib@byteguild.com"
git config --global merge.tool bc3
...
git config --list
git clone git://github.com/schacon/grit.git mygrit
git checkout -- README
Copies the previously committed version of the file over
git add README
Undoing a staged file:
git reset HEAD README
git diff
git diff --staged
git commit
To overwrite the previous commit:
git commit --amend
Changes go from the staging area to the local repository.
git mv README README1
git log
git remote add tib https://github.com/tibonu/test
git remote rm tib
git remote rename tib tonu
git remote -v
git fetch remote-name
Pulls the new versions from the remote to the local repository. Doesn't merge automatically the working area.
git pull remote-name
This is a combined fetch and merge.
git push origin master
origin is the remote master is the branch
git remote show origin
git tag
git tag -a v1.01 -m 'Tib version 1.01'
git tag v1.02
Tags can be created for older commits, after the fact.
Tags aren't pushed by default to remotes, must be pushed specifically:
git push origin v1.5
Pushes tagged version 1.5 including the tag.
git push origin --tags
Pushes all the tags.
git config --global alias.co checkout
git.config --global alias.last 'log -1 HEAD'
git config --global alias.unstage 'reset HEAD --'
git add README
Git will:
git commit -m 'my commit message'
Git generates and stores two more objects:
git ls-files stagehash-object README
54126227aec78e482349aa07164ba3b5436523f0
git ls-files stage
100755 54126227aec78e482349aa07164ba3b5436523f0 0 README```
git show 54126227aec78e482349aa07164ba3b5436523f0
git branch testing
Creates the branch but doesn't switch to it.
git branch
* master
testing
git log --oneline --decorate
d6a6f0f (HEAD -> master, testing) initial commit of my project
git checkout testing
git log --oneline --decorate
d6a6f0f (HEAD -> testing, master) initial commit of my project
HEAD now points to the testing branch
git commit -a -m 'made a change'
git log --oneline --decorate
2f27c95 (HEAD -> testing) made a change
d6a6f0f (master) initial commit of my project
HEAD points to the testing branch, but the current commit is different than the one on the master branch
git checkout master
git merge someotherbranch
git mergetool
git checkout somebranch
git rebase master
The git rebase master command will generate a diff between the current version of master and the common ancestor commit of (master, somebranch) and will inject the changes as a new version in somebranch. After doing this, master can be merged by a fast forward.
git checkout somebranch
vi README
git checkout master
error: Your local changes to the following files would be overwritten by checkout: README
Please, commit your changes or stash them before you can switch branches.
Aborting
You cannot switch the branch because you would lose your changes.
git stash
git checkout master
This works.
git checkout somebranch
git stash list
git stash apply
git Open with Displaying git.