View Categories

Git

1 min read

Git is a popular version control system that allows you to track changes in your codebase, collaborate with others, and manage your project’s history. Here is a list of Git commands from basic to advanced:

Basic Git Commands:

  1. git init: Initializes a new Git repository in the current directory.
  2. git clone <repository URL>: Creates a copy of a remote Git repository on your local machine.
  3. git add <file(s)>: Stages changes for commit.
  4. git commit -m “commit message”: Records staged changes with a descriptive message.
  5. git status: Shows the status of your working directory and staged changes.
  6. git log: Displays a history of commits.
  7. git diff: Shows the differences between the working directory and the last commit.

Branching and Merging:

  1. git branch: Lists all branches in your repository.
  2. git branch <branch_name>: Creates a new branch.
  3. git checkout <branch_name>: Switches to a different branch.
  4. git merge <branch_name>: Merges changes from one branch into the current branch.
  5. git pull: Fetches changes from a remote repository and merges them into the current branch.

Remote Repositories:

  1. git remote -v: Lists remote repositories.
  2. git remote add <name> <URL>: Adds a remote repository.
  3. git push <remote> <branch>: Pushes your changes to a remote repository.
  4. git fetch <remote>: Retrieves changes from a remote repository.
  5. git pull <remote> <branch>: Fetches and merges changes from a remote repository.

Working with Stashes:

  1. git stash: Temporarily saves changes that are not ready to be committed.
  2. git stash pop: Applies the most recent stash and removes it.
  3. git stash list: Lists all stashes.

Advanced Git Commands:

  1. git rebase <branch_name>: Reapplies changes from one branch on top of another.
  2. git cherry-pick <commit>: Applies a specific commit to the current branch.
  3. git reset <commit>: Moves the branch pointer to a specific commit.
  4. git reflog: Shows a log of all Git references.
  5. git submodule: Manages Git submodules within a repository.
  6. git bisect: Helps find a specific commit that introduced a bug.
  7. git filter-branch: Rewrites the repository history using a script.
  8. git remote show <remote>: Displays detailed information about a remote repository.
  9. git blame <file>: Shows the author and revision for each line in a file.
  10. git log –graph –oneline –all: Visualizes the branch history graph.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *