🚀Day 12 Cheat sheet for Git GitHub


📌Configuration

Commands for setting up your name and email globally, so your commits are attributed correctly.

CommandExplanation
git config --global user.name "Your Name"Set your name for commit attribution.
git config --global user.email "youremail@example.com"Set your email for commit attribution.

📌Creating and Cloning Repositories

How to initialize a new Git repository or clone an existing one from a remote source.

CommandExplanation
git initInitialize a new Git repository locally.
git clone <repository-url>Clone a remote repository to your local machine.

📌Staging and Committing

Instructions for adding changes to the staging area and committing them to version control.

CommandExplanation
git add <file>Add a file to the staging area.
git commit -m "message"Commit staged changes with a descriptive message.
git commit -a -m "message"Commit all tracked changes with a message.
git statusView the status of your working directory.
git stashTemporarily store changes that are not ready to commit.
git cherry-pick <commit>Apply a specific commit from another branch.

📌Branching and Merging

How to manage branches, create new ones, switch between them, and merge changes.

CommandExplanation
git branchList all branches in the repository.
git branch <branch-name>Create a new branch.
git checkout <branch-name>Switch to a different branch.
git merge <branch-name>Merge changes from another branch into the current branch.
git pull origin <branch-name>Pull changes from a remote repository.

📌Remote Repositories

Commands to interact with remote repositories, including adding, pushing, fetching, and pulling changes.

CommandExplanation
git remote -vList all remote repositories configured.
git remote add <name> <repository-url>Add a remote repository.
git push <remote> <branch>Push commits to a remote repository.
git fetch <remote>Fetch remote changes without merging.
git pull <remote> <branch>Fetch and merge remote changes.

📌Undoing Changes

Ways to revert or undo changes, whether they're staged, committed, or modified in the working directory.

CommandExplanation
git reset <file>Unstage changes from a file.
git reset --hard HEADDiscard all changes and revert to the last commit.
git checkout -- <file>Discard changes in a file and restore from last commit.
git revert <commit>Create a new commit that undoes a previous commit.

📌History and Logs

How to view commit history and differences, and track the changes introduced in each commit.

CommandExplanation
git logDisplay commit history.
git log --onelineDisplay compact commit history.
git log -pShow commit history with changes introduced.
git diffShow changes between working directory and last commit.
git blame <file>Show who last modified each line in a file.
git log --graphDisplay a graphical representation of commit history.
git reflogView a log of all branch updates and HEAD movements.

📌Rebasing

Move commits to a new base branch interactively or non-interactively.

CommandExplanation
git rebase <base-branch>Reapply commits from the current branch onto another branch.
git rebase -i <commit>Interactive rebase to squash, reword, or reorder commits.

📌Cleaning Untracked Files

Preview and clean untracked files.

CommandExplanation
git clean -nPreview untracked files that can be safely removed.

📌Resetting Commit Position

Move HEAD to a previous commit, keeping changes staged.

CommandExplanation
git reset --soft <commit>Move HEAD to a previous commit, keeping changes staged.

📌Tagging and Releases

Commands for creating and managing tags are often used for marking significant points in your project's history.

CommandExplanation
git tagList all tags in the repository.
git tag -a <tag-name> -m "message"Create an annotated tag with a message.
git push origin <tag-name>Push tags to a remote repository.

📌Managing Remote Branches

Remove remote branches that don't exist remotely.

CommandExplanation
git remote prune originRemove remote branches that no longer exist remotely.

📌Collaboration

Guidelines for collaborating with others, pulling changes from upstream repositories, and working with branches.

CommandExplanation
git remote add upstream <upstream-repo>Add an upstream remote repository.
git pull upstream <branch>Pull changes from an upstream repository.
git checkout -b <new-branch>Create a new branch and switch to it.
git push origin <branch>Push changes to a remote branch.
git merge --no-ff <branch>Merge a branch while keeping a merge commit.

🌟 Conclusion:

Congratulations! 🎉

This comprehensive cheat sheet covers a variety of Git commands categorized into different sections. This Git cheat sheet provides a quick reference to common Git commands and their explanations. Feel free to print or save it for easy access while working with Git repositories.

We hope this blog has given you a Question/Answer 🚀💪

🔍 Did you find this blog helpful? Let us know in the comments below! 👇 And if you have any questions or need further assistance, we're here to help! 🤗

Happy Learning! 💻✨