90 days of devops :Git Basics: Getting Started with Version Control

90 days of devops :Git Basics: Getting Started with Version Control

ยท

2 min read

Git is a powerful tool for version control, enabling developers to track changes, collaborate with teams, and manage project history efficiently. Here are some fundamental Git commands to help you get started:

  1. git init: Initialize a new Git repository in your project directory.

  2. git clone [repository URL]: Clone an existing repository from a remote server to your local machine.

  3. git add [file]: Add changes in a specific file to the staging area.

  4. git add .: Add all changes in the current directory to the staging area.

  5. git commit -m "[commit message]": Commit staged changes with a descriptive message.

  6. git status: Check the status of your working directory and staging area.

  7. git diff: View the difference between the current state and the last commit.

  8. git log: Display a chronological list of commits in the repository.

  9. git branch [branch name]: Create a new branch with the specified name.

  10. git checkout [branch name]: Switch to a different branch in the repository.

  11. git merge [branch name]: Merge changes from a different branch into the current branch.

  12. git push [remote] [branch]: Push local commits to a remote repository.

  13. git pull [remote] [branch]: Fetch changes from a remote repository and merge them into the current branch

Repositories: Centralized vs. Distributed

Git repositories come in two main flavors: centralized and distributed.

  1. Centralized Repository:

    • Follows a client-server model.

    • Typically hosted on a central server (e.g., GitHub, GitLab).

    • Developers clone the repository from the server, make changes locally, and push them back to the server for collaboration.

  2. Distributed Repository:

    • Each developer has a complete copy of the repository.

    • Changes can be synchronized between repositories, allowing for offline work and decentralized collaboration.

    • Commonly used in open-source projects and large-scale development teams.

By mastering these basic Git commands and understanding the different repository models, you'll be well-equipped to manage your projects effectively and collaborate seamlessly with your team members.

Happy coding! ๐Ÿš€

Hope this help you more!

ย