Simple git cheat sheet, base on great udacity git course for beginners and Learn Git with Bitbucket Cloud.
- Git cheat sheet
- Table of content
- Git config
- Git log, checking history of repo.
- Git commit
- Git tag
- Git branching
- Git merge
- Git undoing changes
- Git collaborating
git config user.name "user_name"
git config user.email "user@email.com"
---
git config --global user.name "user_name"
git config --global user.email "user@email.com"git status
git loggit log --oneline #log all commit in one line
git log --stat #log all commit and changed files
git log -p #log all commit and show change in commit
git log --oneline --graph --allgit add . #move all changed file from Working Directory to the Staging Index
git commit -m "Commit message show" #commit
git diff #Show changes that have been made but haven't been committed, yet.Remember about .gitignore file :)
git tag -a v0.1 -m "tag message" #create new tag
git tag -d v0.1 #delete taggit branch #show branch
git branch new-branch master #create new-branch
git checkout new-branch #switch to new-branch
git checkout -b second-branch #create and switch to second-branch
git branch -d new-branch #delete new-branchgit merge second-branch #merge second-branchGit undoing changes another reference.
git commit --amend
# Edit hello.py and main.py git add hello.py git commit
# Realize you forgot to add the changes from main.py git add main.py
git commit --amend --no-editgit revert <SHA-of-commit-to-revert>Reverting creates a new commit that reverts or undo a previous commit. Resetting, on the other hand, erases commits!
git reset <reference-to-commit>three flags:
--mixeddefault (unstages committed changes)--soft(moves committed changes to the staging index)--hard(erase commits)
You've got to be careful with Git's resetting capabilities. This is one of the few commands that lets you erase commits from the repository. If a commit is no longer in the repository, then its content is gone.
To alleviate the stress a bit, Git does keep track of everything for about 30 days before it completely erases anything. To access this content, you'll need to use the git reflog command.