Introduction
Git is a powerful version control system used to track changes in source code, documents, and other digital content. Understanding Git commands is essential for effective collaboration and management of projects.
Basic Git Commands
-
git init
: Initializes a new Git repository. -
git clone
: Clones an existing repository from a remote location. -
git add <file>
: Stages a file for the next commit. -
git add .
: Stages all changes in the current directory. -
git commit -m "<message>"
: Commits changes with a meaningful message. -
git log
: Displays a log of all commits made. -
git status
: Shows the status of changes in the repository. -
git branch <branch-name>
: Creates a new branch. -
git checkout <branch-name>
: Switches to a different branch. -
git merge <branch-name>
: Merges changes from another branch.
Intermediate Git Commands
-
git remote add <name> <url>
: Adds a remote repository. -
git fetch
: Fetches changes from a remote repository. -
git pull
: Fetches and merges changes from a remote repository. -
git push
: Pushes local changes to a remote repository. -
git diff
: Displays differences between commits or files. -
git stash
: Temporarily saves changes to be reapplied later. -
git reset <commit>
: Resets the repository to a specific commit. -
git tag <tag-name>
: Creates a tag for a specific commit.
Advanced Git Commands
-
git rebase
: Reapplies commits on top of another branch. -
git cherry-pick <commit>
: Applies a specific commit to the current branch. -
git submodule
: Manages subprojects within a repository. -
gitk --all
: Visualizes the commit history. -
git clean
: Removes untracked files and directories.
Conclusion
Mastering Git commands is essential for effective version control and collaboration. This article covers basic, intermediate, and advanced Git commands to help you manage your projects efficiently.
Top comments (0)