Essential Git Cheatsheet!
π§ Basic Commands
git init β Initialize a new Git repository.
git clone β Clone a remote repository.
git status β Check the status of your working directory.
git add β Stage changes for commit.
git commit -m "message" β Commit staged changes with a message.
git push β Push your local commits to the remote repository.
git pull β Fetch and merge changes from the remote repo.
git diff β Show changes in the working directory (uncommitted changes).
git diff --staged β Show changes between the staging area and last commit.
π οΈ Branching & Merging
git branch β List branches.
git branch β Create a new branch.
git checkout β Switch to another branch.
git checkout -b β Create and switch to a new branch.
git merge β Merge a branch into the current one.
git branch -d β Delete a branch after merging.
git branch -D β Forcefully delete a branch, even if it hasnβt merged.
π Synchronizatio
git fetch β Download changes from remote without merging.
git rebase β Reapply commits on top of another branch to maintain linear history.
git pull --rebase β Fetch and reapply your changes on top of the latest remote changes.
git remote add β Add a new remote repository.
π― Advanced Git
git stash β Temporarily save changes without committing.
git stash pop β Reapply stashed changes.
git cherry-pick β Apply a specific commit to your current branch.
git log --oneline β View simplified commit history.
git reflog β Show the history of your reference changes (e.g., checkout, resets).
git log --graph --decorate --all β Show a visual commit history.
π¨ Undoing Changes
git reset β Unstage a file.
git reset --soft β Reset to a commit but keep changes in the working directory.
git reset --hard β Completely reset to a previous commit, discarding changes.
git revert β Create a new commit that undoes a specific commit.
βοΈ Collaborating with Others
git fork β Fork a repository on GitHub (via UI) to start contributing.
git pull origin β Pull changes from the original remote branch.
git push origin β Push your branch to the original repository for collaboration.
Over to you: did we miss anything?
Top comments (0)