Basic Git commands

John Akpakwu - Jul 28 - - Dev Community

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

  1. git init: Initializes a new Git repository.
  2. git clone: Clones an existing repository from a remote location.
  3. git add <file>: Stages a file for the next commit.
  4. git add .: Stages all changes in the current directory.
  5. git commit -m "<message>": Commits changes with a meaningful message.
  6. git log: Displays a log of all commits made.
  7. git status: Shows the status of changes in the repository.
  8. git branch <branch-name>: Creates a new branch.
  9. git checkout <branch-name>: Switches to a different branch.
  10. git merge <branch-name>: Merges changes from another branch.

Intermediate Git Commands

  1. git remote add <name> <url>: Adds a remote repository.
  2. git fetch: Fetches changes from a remote repository.
  3. git pull: Fetches and merges changes from a remote repository.
  4. git push: Pushes local changes to a remote repository.
  5. git diff: Displays differences between commits or files.
  6. git stash: Temporarily saves changes to be reapplied later.
  7. git reset <commit>: Resets the repository to a specific commit.
  8. git tag <tag-name>: Creates a tag for a specific commit.

Advanced Git Commands

  1. git rebase: Reapplies commits on top of another branch.
  2. git cherry-pick <commit>: Applies a specific commit to the current branch.
  3. git submodule: Manages subprojects within a repository.
  4. gitk --all: Visualizes the commit history.
  5. 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.

.
Terabox Video Player