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:
git init: Initialize a new Git repository in your project directory.
git clone [repository URL]: Clone an existing repository from a remote server to your local machine.
git add [file]: Add changes in a specific file to the staging area.
git add .: Add all changes in the current directory to the staging area.
git commit -m "[commit message]": Commit staged changes with a descriptive message.
git status: Check the status of your working directory and staging area.
git diff: View the difference between the current state and the last commit.
git log: Display a chronological list of commits in the repository.
git branch [branch name]: Create a new branch with the specified name.
git checkout [branch name]: Switch to a different branch in the repository.
git merge [branch name]: Merge changes from a different branch into the current branch.
git push [remote] [branch]: Push local commits to a remote repository.
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.
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.
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!