A Quick Guide: Essential Git Commands
Navigating Your Code Journey with Fundamental Git Commands ๐๐ป
Table of contents
Introduction:
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.
Example:
$ 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.
Example:
$ 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.
Example:
$ 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.
Example:
$ git status
- View Commit History: To review the commit history, use "git log." This displays a list of all commits with their details.
Example:
$ git log
- Create a New Branch: With "git branch," you can create a new branch to work on separate features or fixes.
Example:
$ git branch feature-branch
- Switch Branches: To move between branches, use "git checkout."
Example:
$ git checkout feature-branch
- Merge Branches: When you're done with your changes, merge them back into the main branch using "git merge."
Example:
$ git merge feature-branch
Conclusion:
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! ๐๐ป
ย