Git is a powerful version control system widely used by developers to manage and track changes in their projects. Understanding Git commands is essential for efficient collaboration and project management. In this article, we'll explore some fundamental Git commands with examples to help you get started.
Git Command Examples:
1. git init
Initialize a new Git repository in the current directory.
git init
2. git clone
Clone a repository into a new directory.
git clone repository_url
3. git add
Add file contents to the index for staging.
git add filename
4. git commit
Record changes to the repository.
git commit -m "Commit message"
5. git push
Push commits to a remote repository.
git push remote_name branch_name
6. git pull
Fetch from and integrate with another repository or a local branch.
git pull remote_name branch_name
7. git branch
List, create, or delete branches.
git branch
8. git checkout
Switch branches or restore working tree files.
git checkout branch_name
9. git merge
Join two or more development histories together.
git merge branch_name
10. git status
Show the status of working tree files.
git status
11. git log
Show commit logs.
git log
12. git reset
Reset current HEAD to the specified state.
git reset commit_hash
13. git fetch
Download objects and refs from another repository.
git fetch remote_name
14. git remote
Manage set of tracked repositories.
git remote -v
15. git tag
Create, list, delete or verify a tag object signed with GPG.
git tag tag_name
These are just a few basic Git commands to get you started. As you become more familiar with Git, you'll discover a wide range of commands and options to suit your workflow.
Remember, practice makes perfect! Don't hesitate to experiment with Git commands in a safe environment to deepen your understanding.
Happy coding!