Git cheatsheet
Basic tasks
- Clone a repository, clone a repo in a dir:
$ git clone https://github.com/neojal/neojal.github.io.git
$ git clone https://github.com/neojal/neojal.github.io.git directory
- Create branch and switch to it:
$ git checkout -b edition
- Show current branch, show all branches:
$ git branch
$ git branch -a
- Switch to other branch, to master:
$ git checkout master
- Show working tree status:
$ git status
- Add contents to the index of the working tree:
$ git add file.md
$ git add .
- Rewrite edition branch with master:
$ git checkout edition
$ git rebase master
- Merge edition branch into master:
$ git checkout master
$ git merge edition
- Preserve our current changes and make rollback:
# make new branch to save current code
$ git branch current-changes
# and reset to needed commit
$ git reset --hard commit-id