๐What is Git?
Git ๐: The Friendly Code Octopus
Git is like a magical octopus that helps teams of people work on the same project without stepping on each other's toes.
Imagine you're working on a cool project with friends, and everyone's making changes to the code ๐. Git helps you keep track of those changes and makes sure everything stays organized.
Think of it as a magical time-traveling tool. With Git, you can go back โช๐ค in time to see how your code looked yesterday or even a month ago. ๐ Mistakes happen, but Git lets you fix them and save the day!
Also, sharing your code with others becomes a breeze๐. Git lets you share it with the world, i.e anyone can use code from anywhere! ๐
So, Git is like a coding wizard that keeps your projects tidy, helps you undo mistakes, and lets you collaborate like a superhero team! ๐
Here's how it works:
Repository ๐:
- Think of it as a folder where your project lives.
Commits ๐:
- Each time you make a change to the code, Git records it as a "commit." It's like taking a snapshot of the code at that moment.
Branches ๐ฟ:
- You can create branches to try out different ideas without messing up the main code. It's like sketching a new idea on a separate piece of paper before adding it to the big canvas.
Merge ๐ค:
- Once you're happy with your branch you can merge it back into the main code. Git helps you blend everything together seamlessly.
Pull Request ๐:
- If you're working with others, you might make a "pull request" to suggest adding your changes to the main code. It's like saying, "Hey, check out this awesome addition I made!"
Push and Pull ๐:
- When you're ready to share your changes or get the latest updates from others, you "push" or "pull" the changes. It's like updating your code with everyone else's latest updated code.
Forks ๐ด:
- If you find a cool code someone else built and you want to add your touches, you can make a "fork." It's like creating your copy to play with.
๐What is GitHub?
GitHub, a web-based haven for code collaboration, hosts version control using the power of Git. Nestled under the Microsoft umbrella, it not only embraces Git's distributed version control and source code management wizardry but adds its own special features to the mix. ๐ธ๏ธ๐ป
Popular among developers, GitHub serves as a bustling town square where coders gather to share ideas and collaborate on projects. ๐ค๐ก It doubles as a scenic landscape for hosting open-source projects, providing a vibrant stage for the global coding community. ๐๐
So, whether you're sculpting code masterpieces or contributing to open-source symphonies, GitHub is your digital canvas, buzzing with creativity and camaraderie. ๐จ๐ฉโ๐ป๐จโ๐ป
๐What is Version Control? How many types of version controls do we have?
Version control is like a time-travelling magic wand for coders. It helps keep track of changes in your code over time without messing up your original draft, letting you rewind, fast-forward, and collaborate seamlessly. ๐ฐ๏ธโจ
Local Version Control ๐ก:
- It's like having a personal diary for your code on your computer. You can track changes, but it's a solo adventure without sharing with others.
Centralized Version Control ๐:
- Imagine a shared notebook everyone in your team can access. Centralized version control lets multiple people collaborate on the same project, with a central hub storing all changes.๐๐ซ
Distributed Version Control ๐๐ป:
- Take that shared notebook, make a copy for everyone, and let them work independently. That's distributed version controlโlike Git. Everyone has their version, and changes sync up later.
Version control ensures that your coding story is well-documented and everyone stays on the same page, avoiding coding chaos! ๐๐ฅ
๐Why do we use distributed version control over centralized version control?
Distributed Version Control ๐:
Independence ๐ค :
- In distributed version control, each coder has their own complete copy of the code and its history. It's like having your own sandbox to play in without waiting for permission. ๐๏ธ๐ฉโ๐ป
Offline Awesomeness ๐ด:
- Imagine you're on a coding adventure in a remote coding island with no internet. With distributed version control, you can still make changes, commit, and save your progress locally. Later, when you're back online, you can share your coding tales with the rest of the world. ๐๏ธ๐
Collaboration Charm ๐ซ:
- Collaboration is a breeze! Each coder's copy is a full-fledged hero with the entire code history. They can work independently and merge their changes smoothly, creating a symphony of code creativity. ๐ป๐ฉโ๐ป๐จโ๐ป
Centralized Version Control ๐:
Single Source of Truth ๐ฅ:
- In centralized version control, there's one central hub (repository) that holds the entire code history. It's like the library where everyone goes to read and write. ๐๐ฅ
Simplicity ๐ฏ:
- It's straightforward! There's one version, and everyone works on it. Changes are made directly in the central hub. Simple, like everyone dancing to the same rhythm in a tango. ๐๐บ
In the end, whether you choose distributed or centralized version control depends on your coding flavour. Distributed offers flexibility and independence, while centralized brings simplicity and a clear central hub. In essence, distributed version control offers more magical independence and flexibility. Coders can weave their coding spells independently, merging their enchantments later for a harmonious magical kingdom of code! ๐๐ป๐ฎ
๐Git Commands Cheatsheet
git init
To initialize an empty git repository .git
git status
To check what changes have been made
git add filename/git add .
To maintain the changes made, to keep it in the project history
git diff
Tells what are exact changes made
git commit -m "message"
To commit changes made
git restore --staged filename
To remove saved changes without committing them
git log
To check history
git reset --hard commit_id
To go back to the previous version
git stash
To stash an item(To keep in temporary storage)
git stash list
To see the stashed items list
git stash pop
To get changes previously made
git stash clear
To clear the stashed items
git clone <url of git repo>
To clone the repository from GitHub to the local machine
git pull origin <branch>
To fetch changes from the specified branch on the remote repository and merge them into your current local branch.
git push origin <branch>
To push local commits to a remote branch on GitHub
git tag -a <tagname> -m <message> <commit_id>
To apply tag
git tag
To see the list of tags
git show <tagname>
To see particular commit content by using the tag
git tag -d <tagname>
To delete a tag
git branch
To list all branches in the repository
git checkout <branch>
To switch to a different branch
git merge <branch>
To merge changes from a specific branch into the current branch
git log --oneline
Displays a condensed history of commits, showing each commit as a single line with a shortened commit hash and commit message.
"๐ Thank you for taking the time to explore this blog!๐ I hope you found the information both helpful and insightful.โจ
๐ Enjoy your learning journey, and don't hesitate to reach out if you have any feedback. ๐ค Happy exploring!"