Day 8 Task: Basic Git & GitHub for DevOps Engineers.

Day 8 Task: Basic Git & GitHub for DevOps Engineers.

ยท

6 min read

๐Ÿ“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:

  1. Repository ๐Ÿ“:

    • Think of it as a folder where your project lives.
  2. 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.
  3. 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.
  4. Merge ๐Ÿค:

    • Once you're happy with your branch you can merge it back into the main code. Git helps you blend everything together seamlessly.
  5. 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!"
  6. 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.
  7. 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. ๐Ÿ•ฐ๏ธโœจ

  1. 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.
  2. 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.๐Ÿ“œ๐Ÿ‘ซ
  3. 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 ๐ŸŒ:

  1. 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. ๐Ÿ–๏ธ๐Ÿ‘ฉโ€๐Ÿ’ป
  2. 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. ๐Ÿ๏ธ๐ŸŒ
  3. 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 ๐ŸŒ:

  1. 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. ๐Ÿ“š๐Ÿ‘ฅ
  2. 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

  1. git init

    To initialize an empty git repository .git

  2. git status

    To check what changes have been made

  3. git add filename/git add .

    To maintain the changes made, to keep it in the project history

  4. git diff

    Tells what are exact changes made

  5. git commit -m "message"

    To commit changes made

  6. git restore --staged filename

    To remove saved changes without committing them

  7. git log

    To check history

  8. git reset --hard commit_id

    To go back to the previous version

  9. git stash

    To stash an item(To keep in temporary storage)

  10. git stash list

    To see the stashed items list

  11. git stash pop

    To get changes previously made

  12. git stash clear

    To clear the stashed items

  13. git clone <url of git repo>

    To clone the repository from GitHub to the local machine

  14. git pull origin <branch>

    To fetch changes from the specified branch on the remote repository and merge them into your current local branch.

  15. git push origin <branch>

    To push local commits to a remote branch on GitHub

  16. git tag -a <tagname> -m <message> <commit_id>

    To apply tag

  17. git tag

    To see the list of tags

  18. git show <tagname>

    To see particular commit content by using the tag

  19. git tag -d <tagname>

    To delete a tag

  20. git branch

    To list all branches in the repository

  21. git checkout <branch>

    To switch to a different branch

  22. git merge <branch>

    To merge changes from a specific branch into the current branch

  23. 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!"

ย