Skip to content

Instantly share code, notes, and snippets.

@carlosbazilio
Created September 23, 2020 15:35
Show Gist options
  • Save carlosbazilio/4b91729c19d022508e06a4278a990808 to your computer and use it in GitHub Desktop.
Save carlosbazilio/4b91729c19d022508e06a4278a990808 to your computer and use it in GitHub Desktop.
YA Git Cheat Sheet
=> States:
Work Directory (Working Tree) —add—>
Stage Area (Index) —commit—>
Local Repository (HEAD) —push—>
Remote Repository
=> HELP:
git <command> --help // List a man help of the git command
=> Initializing
git init // Create a repository; folder /.git contains all of the config of git
git config --global user.name bazilio // Uses the same name of github user
git config --global user.email carlosbazilio@gmail.com
git clone <url> // Copy from Repositório to Diretório local
git remote -v // List the remote projects (Repositórios)
git remote add origin https://github.com/try-git/try_git.git // Add a remote repository and name it origin
git ignore
https://www.atlassian.com/git/tutorials/gitignore
=> Doing The Basics
git add <files> // Add files to the repository
git add -f <files> // Add ignored files (.gitignore)
git commit -am <comment> // Add files to Stage and confirm the modifications with comment
git push -u origin master // Copy modified files to the remote repository
git push // Copy modified files to the remote repositor using default parameters
git pull // fetch + merge; Used to combine branches
git pull upstream master // Combine from upstream branch to master branch
git rm <files> // Remove files from Diretório and Stage (?)
git checkout -- <files> // Copy files back from Stage to Diretório
=> Inspecting
git status // To verify the status of files in a git directory
git log // History of commands, commits
git log --name-status // History of commands with filenames
git log --oneline // Succint output
git log --graph // Visual graph of branches
git diff HEAD // Get the differences in the repository from our last commit
git diff --staged // Get the differences in the staged from our last commit
git difftool // A visual tool for diff
git show // Get the differences between unmodified versions
git reflog // View undo history
=> Branching
git branch // Lists created branches and the selected one
git branch <name> // Creates a branch called <name>
git branch -d <name> // Deletes a branch called <name>
git merge <name> // Merge <name> branch with the current one
git merge --abort // Aborts executing the current merge
git checkout -b <new-branch-name> // Create a new branch based on the current branch
git checkout <branch-name> // Switch to branch-name
=> Versioning
git tag v.1.0.0 // Create a tag version "v.1.0.0" in order to be regarded on a git reset command, for instance
git stash // Save the current dirty version of working directory to a stack of modifications. Turn local status empty
git stash apply // Recover from stack last dirty version saved with stash
git stash list // List all saved dirty versions
git reset <hash number from log> // Recover an old version of stage; we need to run checkout to update local folder (Diretório)
git reset --hard <hash number from log> // Do the same as previous without requiring checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment