Git, a powerful version control system, plays a pivotal role in managing code repositories and collaborating with developers. In this brief blog, we'll cover some fundamental Git commands along with practical examples to help you get started on your version control journey.
- Initialize a Repository: To begin using Git, create a new repository with the "git init" command. This sets up a local repository in your project directory.
$ git init
- Add Files to the Staging Area: Use "git add" to stage files for commit. This prepares them for inclusion in the next commit snapshot.
$ git add file1.txt file2.html
- Commit Changes: With "git commit," create a snapshot of the changes in the staging area. Add a descriptive message to document the changes made.
$ git commit -m "Added new feature and fixed bugs"
- Check Status: To see the current status of your repository, employ "git status." This shows which files are modified, staged, or not tracked.
$ git status
- View Commit History: To review the commit history, use "git log." This displays a list of all commits with their details.
$ git log
- Create a New Branch: With "git branch," you can create a new branch to work on separate features or fixes.
$ git branch feature-branch
- Switch Branches: To move between branches, use "git checkout."
$ git checkout feature-branch
- Merge Branches: When you're done with your changes, merge them back into the main branch using "git merge."
$ git merge feature-branch
These basic Git commands and examples will help you navigate through the version control process effectively. Git offers much more functionality to support efficient code collaboration and management. As you delve deeper into the Git world, you'll uncover a vast array of features to enhance your development workflow. Happy coding! 🚀💻
Did you find this article valuable?
Support Mansi Jani by becoming a sponsor. Any amount is appreciated!