🚀Day 12 Cheat sheet for Git GitHub
📌Configuration
Commands for setting up your name and email globally, so your commits are attributed correctly.
Command | Explanation |
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.
Command | Explanation |
git init | Initialize 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.
Command | Explanation |
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 status | View the status of your working directory. |
git stash | Temporarily 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.
Command | Explanation |
git branch | List 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.
Command | Explanation |
git remote -v | List 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.
Command | Explanation |
git reset <file> | Unstage changes from a file. |
git reset --hard HEAD | Discard 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.
Command | Explanation |
git log | Display commit history. |
git log --oneline | Display compact commit history. |
git log -p | Show commit history with changes introduced. |
git diff | Show changes between working directory and last commit. |
git blame <file> | Show who last modified each line in a file. |
git log --graph | Display a graphical representation of commit history. |
git reflog | View a log of all branch updates and HEAD movements. |
📌Rebasing
Move commits to a new base branch interactively or non-interactively.
Command | Explanation |
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.
Command | Explanation |
git clean -n | Preview untracked files that can be safely removed. |
📌Resetting Commit Position
Move HEAD to a previous commit, keeping changes staged.
Command | Explanation |
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.
Command | Explanation |
git tag | List 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.
Command | Explanation |
git remote prune origin | Remove remote branches that no longer exist remotely. |
📌Collaboration
Guidelines for collaborating with others, pulling changes from upstream repositories, and working with branches.
Command | Explanation |
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! 💻✨