Git and GitHub Cheatsheet😎: A Comprehensive Guide for Beginners and Experts🔥
Table of contents
- 😎Git and GitHub cheat sheet😎:
- git init
- git clone [url]
- git add [file/directory]
- git commit -m "message"
- git status
- git log
- git push [remote] [branch]
- git pull [remote] [branch]
- git branch
- git checkout [branch]
- git merge [branch]
- git remote -v
- git fetch [remote]
- git reset [file]
- git revert [commit]
- git diff [file]
- git tag [name]
- git stash
- git remote add [remote_name] [remote_url]
- git remote rm [remote_name]
- git branch -d [branch_name]
- git push --tags
- git merge --no-ff [branch_name]
- git cherry-pick [commit_id]
- git log --oneline
- git fetch --all
- git clone --depth 1 [url]
- git commit --amend
- git rebase [branch_name]
- git log --graph
- git tag -a [tag_name] -m "[message]"
- git push [remote] :[branch_name]
- git blame [file_name]
- git log --author="[author_name]"
- git commit -a -m "[message]"
- git diff [commit_id_1] [commit_id_2]
- git reset --hard [commit_id]
- git stash pop
- git show [commit_id]
- git stash list
- git revert [commit_id]
- git remote -v
- git branch -m [old_branch_name] [new_branch_name]
- git fetch [remote] [branch]
- git submodule add [repository_url] [submodule_path]
- git merge --abort
- git cherry-pick -n [commit_id]
- git commit --allow-empty -m "[message]"
- git bisect start
- git config --global [key] [value]
- git grep [pattern]
- Where can you write these commands
- Conclusion
🔥Greetings, fellow humans,🙋♂️ and welcome to the world of Git and Github! If you're here, it probably means that you've already been initiated into the world of coding and software development🙃, and you've discovered that Git is the ultimate tool for version control. Or maybe you just stumbled upon this blog by accident, in which case, congratulations on your good luck!
Now, you might be thinking, "What the heck is Git, and why should I care?" Well, my dear friend, Git is like the Swiss Army Knife of version control. It can do everything from tracking changes in your code to collaborating with other developers on a project. It's so versatile that even your grandma can use it. (Okay, maybe not your grandma, but you get the point.🙃)
And if you're wondering what Github is, it's like the Facebook of the coding world. It's a social network for developers😲, where you can share your code with the world😎, collaborate with other developers, and showcase your skills to potential employers. Plus, you get to collect shiny little stars (a.k.a. "stars") on your projects, which is the ultimate measure of your awesomeness.
But wait, there's more! Git and Github are not just useful, they're also fun! You get to spend hours resolving merge conflicts, pulling your hair out when your code won't compile, and cursing at your computer when Git decides to randomly break things. It's like a rollercoaster ride, but for your emotions.
So, buckle up, my friends, and get ready to dive into the wonderful world of Git and Github. It's going to be a wild ride, but I promise you, it'll be worth it.
😎Git and GitHub cheat sheet😎:
git init
This command initializes a new Git repository in the current directory.
git clone [url]
This command clones an existing Git repository to your local machine.
git add [file/directory]
This command adds changes to the staging area. You can add specific files or directories, or use a wildcard to add all changes.
git commit -m "message"
This command creates a new commit with the changes added to the staging area. The message describes the changes made.
git status
This command shows the status of the working directory and the staging area. It shows which files are modified, which are staged, and which are untracked.
git log
This command shows a log of all the commits in the current branch. It shows the author, date, and commit message.
git push [remote] [branch]
This command pushes the commits in the current branch to a remote repository. You can specify the remote and branch to push to.
git pull [remote] [branch]
This command pulls the changes from a remote repository into the current branch. You can specify the remote and branch to pull from.
git branch
This command shows a list of all the branches in the repository. The current branch is highlighted with an asterisk.
git checkout [branch]
This command switches to the specified branch. You can create a new branch with the -b flag.
git merge [branch]
This command merges the specified branch into the current branch. It creates a new commit with the changes from both branches.
git remote -v
This command shows a list of all the remote repositories associated with the current repository.
git fetch [remote]
This command fetches the changes from a remote repository without merging them into the current branch.
git reset [file]
This command removes changes from the staging area. You can specify a specific file or use a wildcard to remove all changes.
git revert [commit]
This command creates a new commit that undoes the changes made in the specified commit.
git diff [file]
This command shows the differences between the working directory and the staging area, or the staging area and the last commit.
git tag [name]
This command creates a new tag for the current commit. Tags are used to mark specific points in the history of the repository.
git stash
This command saves changes to a temporary stash so you can switch branches or work on something else. You can apply the stash later with git stash apply.
git remote add [remote_name] [remote_url]
This command adds a new remote repository to the current Git repository. You can specify the remote name and the URL of the remote repository.
git remote rm [remote_name]
This command removes a remote repository from the current Git repository. You need to specify the remote name that you want to remove.
git branch -d [branch_name]
This command deletes a local branch. You need to specify the name of the branch that you want to delete.
git push --tags
This command pushes all tags to the remote repository.
git merge --no-ff [branch_name]
This command merges a branch into the current branch with a new commit, even if the merge is a fast-forward merge.
git cherry-pick [commit_id]
This command applies the changes from a specific commit to the current branch.
git log --oneline
This command shows a simplified log of all the commits in the current branch. It shows the commit ID and the commit message.
git fetch --all
This command fetches all changes from all remote repositories.
git clone --depth 1 [url]
This command clones a repository with only the latest commit. This is useful if you only need the latest version of the repository and don't want to download the entire history.
git commit --amend
This command changes the most recent commit. It opens the commit message editor, and you can edit the commit message or add more changes to the commit.
git rebase [branch_name]
This command changes the base of the current branch to the specified branch. It replays the changes made in the current branch on top of the specified branch.
git log --graph
This command shows a visual representation of the commit history as a graph. It shows the branches and the commits in a more intuitive way.
git tag -a [tag_name] -m "[message]"
This command creates a new annotated tag for the current commit. Annotated tags include a message and other metadata, such as the author and the date.
git push [remote] :[branch_name]
This command deletes a remote branch. You need to specify the remote name and the branch name that you want to delete.
git blame [file_name]
This command shows who made changes to each line of a file and when. It's useful to track the authorship of the changes and to find who introduced a bug or a feature.
git log --author="[author_name]"
This command shows a log of all the commits made by a specific author. You need to specify the author's name in quotes.
git commit -a -m "[message]"
This command adds and commits all changes in the working directory in one step. It's useful for small changes that don't need to be staged separately.
git diff [commit_id_1] [commit_id_2]
This command shows the differences between two commits. You need to specify the IDs of the commits that you want to compare.
git reset --hard [commit_id]
This command resets the current branch to the specified commit. It discards all changes made after that commit and can't be undone.
git stash pop
This command applies the most recent stash to the current branch and removes it from the stash list.
git show [commit_id]
This command shows the details of a specific commit. It shows the commit message, author, date, and changes made in that commit.
git stash list
This command shows a list of all stashes in the current repository. Each stash has a unique identifier that can be used to apply or delete it.
git revert [commit_id]
This command creates a new commit that undoes the changes made in a specific commit. It's useful to undo a commit without discarding the changes made after it.
git remote -v
This command shows a list of all remote repositories and their URLs. It's useful to check if you have the correct remotes and if they are up-to-date.
git branch -m [old_branch_name] [new_branch_name]
This command renames a local branch. You need to specify the old and new names of the branch.
git fetch [remote] [branch]
This command fetches changes from a specific remote repository and branch. It's useful to update your local repository with changes made by other contributors.
git submodule add [repository_url] [submodule_path]
This command adds a new submodule to the current repository. A submodule is a separate Git repository that can be used as a dependency in the main repository.
git merge --abort
This command aborts a merge that has conflicts. It restores the repository to the state before the merge started.
git cherry-pick -n [commit_id]
This command applies the changes from a specific commit to the current branch without creating a new commit. It's useful to apply changes selectively or to modify the changes before committing them.
git commit --allow-empty -m "[message]"
This command creates an empty commit with a specific message. It's useful to mark a milestone or to trigger a build or a deployment.
git bisect start
This command starts a binary search between two commits to find the commit that introduced a bug or a regression. It's useful to locate the source of a problem in a large codebase.
git config --global [key] [value]
This command sets a global configuration option for Git. You can use it to customize your Git environment, such as your name, email, or default editor.
git grep [pattern]
This command searches for a specific text pattern in the entire repository or a specific file. It's useful to find references to a variable, a function, or a string.
Where can you write these commands
So, you've learned all these amazing Git commands, but where can you actually write them?🤔🤔 The answer is simple: anywhere you can type on your computer!🙃
Yes, that's right. You can write Git commands in your favorite text editor, in your terminal, in your browser's console, on a sticky note, or even on the back of your hand. (Disclaimer: we don't recommend the last option, as it may result in smudged ink and confusion.🙃)
In all seriousness😲, the most common place to write Git commands is in your terminal or command prompt. But hey, if you want to mix things up and write Git commands on your fridge, who are we to judge?🫠
Conclusion
And there you have it, my friends!😎 You're now equipped with a comprehensive Git and Github cheat sheet that covers all the basics and more. You're practically a Git wizard now, and you should feel proud of yourself for making it this far.
But before you go off into the world of coding and software development, let me leave you with a few words of wisdom: Git is powerful🔥, but with great power comes great responsibility🫠. Don't be that developer who accidentally deletes the entire codebase with one wrong command (we've all been there, trust me😂😂).
Also, don't forget to have fun with Git and Github. Don't take it too seriously. After all, coding is just a bunch of 1s and 0s arranged in a specific way, right? So, don't be afraid to experiment, make mistakes, and learn from them.
And if all else fails, just remember to blame Git. It's always Git's fault.
So, go forth, my friends, and may Git be with you!
Peace out Guys🙃, Happy Coding😎😎!!!