Let’s dive into the world of Git commands.
Git, the distributed version control system, has become an indispensable tool for developers worldwide. Whether you’re a seasoned pro or just starting, understanding fundamental Git commands is crucial. Let’s explore the basics with clear explanations and examples.
This tutorial covers the most common git commands, from initializing a repository to pushing changes to a remote
1. git init
This command initializes a new Git repository. It creates a hidden subfolder within your existing directory that houses the internal data structure required for version control.
git init
2. git clone
To create a copy of a remote repository on your local machine, use git clone
.
git clone <repository_url>
3. git add
The git add
command stages changes for commit. You can add specific files or all changes.
git add <file_name>
4. git commit
Commits changes to the local repository along with a descriptive message.
git commit -m "Your message here"
5. git status
Check the status of your working directory. It shows modified files and those staged for commit.
git status
6. git pull
Update your local repository with changes from the remote repository.
git pull origin <branch_name>
7. git push
Push your local changes to the remote repository.
git push origin <branch_name>
8. git branch
List, create, or delete branches in your repository.
git branch
git branch <new_branch_name>
git branch -d <branch_name>
9. git merge
Combine changes from different branches.
git merge <branch_name>
10. git log
View the commit history.
git log
11. git diff
Display changes between commits or the working directory.
git diff
git diff <commit_id1> <commit_id2>
12. git remote
Manage connections to remote repositories.
git remote -v
git remote add <remote_name> <repository_url>
These basic Git commands provide a solid foundation for version control. As you progress, you’ll encounter more advanced commands and strategies. Remember, mastering Git is a journey, so keep experimenting and learning!
Visit our Github Repository and start your journey of git
Happy coding! 🚀