git init
: initialize current folder as a git repository
git clone <URL>
: brings the git repo from
git status
: tells us what we need to know about our repository
git add <FILE>
: adds
git commit
: open a text editor to write commit message
git commit -m "MESSAGE"
: writes MESSAGE as a commit without a text editorgit log
: shows the log (history) of our commits
git log --oneline
: shows the shorter oneline commitgit diff
: compare current uncommited state with last known git state
git diff --staged
: runs git diff between the staging area and last known stategit diff HEAD~<NUMBER>
: compares HEAD with commit
git diff <HASH>
: compares HEAD with the commit in
git restore --source <HASH OR HEAD~> <FILE>
: restore file to <HASH OR HEAD~>
git checkout <HASH OR HEAD~> <FILE>
: restores file to <HASH OR HEAD~>
git checkout main
: go back to maingit switch main
: go back to maingit remote add <NAME> <URL>
: adds the git remote rm <NAME>
: removes the remote called git remote -v
: look at all the remotes you havegit push <WHERE> <WHAT>
: pushes the git push origin main
git pull <WHERE> <WHAT>
: pulls the git branch <NAME>
: create branch
git switch <NAME>
: move to the branch
git checkout <NAME>
: also move to the branch git swich -c <NAME>
: create and move to the branch
git checkout -b <NAME>
: also create and move to branch git merge <BRANCH>
: merge
git rebase
: command to change the history of a commit
git merge
can be automatically combinedgit rebase <BRANCH>
: incorporate changes from
git status
: is your friendgit add <FILE>
: to mark conflict resolutiongit rebase --continue
: move to next commit in rebasegit rebase --abort
: undo git rebase stepgit rebase -i <COMMIT>
HEAD~
or
squash
/s
git rebase -i <HASH>^
: use ^ to include that commit in interactive rebasegit stash
or git commit
: to save work before moving branches
stash
is temporarygit stash list
: see your stashed commitsgit stash apply
: apply your last stashed commitgit stash clear
: clean up your stashesA merge
on the remote is called a "pull request" or "merge request"
git push <WHERE> <WHAT>
push
A merge conflict can happen after a PR is issued.
git fetch
: update your git log without making any changes to your files
git fetch --prune
: update your log and also remove deleted remote branchesgit push -f <WHERE> <WHAT>
: force push to the remote
git push --force-with-lease <WHERE> <WHAT>
: more mindful of collaboratorsgit clone <URL>
to get repo on their computerorigin
: is your own remote copyupstream
: is the original copy