Git Cheat Sheet

From Wayne's Dusty Box of Words
Revision as of 18:28, 22 October 2020 by Wprecht (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Setup & Connections
git remote add origin <YourRemoteURL> Connect to a remote repository
git remote -v List remote link
git remote rm <YourRemoteURL> Remove remote link
git config --[local | global] user.name Display the committer name in gitconfig
git config --[local | global] user.email Display the committer email in gitconfig
git config --[local | global] user.name "Your Name" Set the committer name in gitconfig
git config --[local | global] user.email "Your Email" Set the committer email in gitconfig
Tracking & Staging Files
git status Shows you your current branch and changed files
git diff <ChangedFileName> Shows the changes in the file
git add <ChangedFileName> Stages a particular file
git reset HEAD <ChangedFileName> Unstages a particular file
git reset --hard Resets the entire branch to head
git reset --hard <Commit_ID> Resets the entire branch to before that commit
git add . Stage all changed files
Commit, Log & Push Files
git commit -m "Message" Creates a commit with that message
git push origin <YourBranchName> If the branch exists on remote omit YourBranchName
git push -u origin <YourBranchName> set upstream branch using the git push command
git log Lists all logs step by step
git log --oneline Plain list of commits
Branching
git branch <BranchName> Creates a branch
git push origin <BranchName> push the branch to remote
git push origin --delete <YourBranchName> deletes the branch from remote
git branch -r Lists all remote branches
git branch Lists all local branches
git branch -a Lists all local & remote branches
git checkout -b <BranchName> Checkout to local branch
git branch -d <BranchName> Deletes branch
git branch -d <BranchName1> <BranchName2> <BranchName3> Deletes multiple branches
git merge <YourLocalBranch> merges local branch
git merge origin <YourRemoteBranch> merges remote branch
git fetch --prune align remote branch with local
Staging
git stash save <MyStashName> Stashes all staged changes
git stash list List all stashes (w/ IDs)
git stash drop stash@(ID) Removes that stash
git stash clear Removes ALL stashes
git stash apply stash@(ID) Merges that shash to the current branch
git stash merge stash@(ID) Immediate merge, not recommended
Reverts & Updates
git log --onetime Lists all of your commits. Copy <commit hash> from list
git stash revert <ID> reverts that commit
git commit --amend --no-edit Fix a commit by git add ./ and them this to update the previous commit