Day 12 of #90DaysOfDevOps

Day 12 of #90DaysOfDevOps

·

2 min read

Git commands cheatsheet


Getting Started:

  1. git init - Initializes a new Git repository in the current directory.

  2. git clone <url> - Creates a local copy of a remote repository specified by the URL.

  3. git config -l - To check configuration fo the git

  4. git config --global user.name <your name> - To configure your username on git

  5. git config --global user.email <your email> - To configure your email on git

Basic Workflow:

  1. git add <file> - Stages changes in a specific file for the next commit.

  2. git add . - Stages changes in all tracked files for the next commit.

  3. git commit -m "<commit message>" - Commits changes with a specified message.

  4. git status - Shows the current state of the repository, including any untracked or modified files.

  5. git diff - Shows the differences between the current changes and the previous commit.

  6. git log - Shows the commit history of the repository.

Branches:

  1. git branch - Shows a list of all branches in the repository.

  2. git branch <branch-name> - Creates a new branch with the specified name.

  3. git checkout <branch-name> - Switches to the specified branch.

  4. git merge <branch-name> - Merges the specified branch into the current branch.

  5. git branch -d <branch-name> - Deletes the specified branch.

Remote Repositories:

  1. git remote add <remote-name> <remote-url> - Adds a new remote repository.

  2. git remote -v - Shows a list of all remote repositories and their URLs.

  3. git push <remote-name> <branch-name> - Pushes local changes to a remote repository.

  4. git pull <remote-name> <branch-name> - Pulls remote changes to the local repository.

Miscellaneous:

  1. git rm <file> - Removes a file from the repository.

  2. git reset - Resets the repository to the previous commit.

  3. git tag <tag-name> - Creates a new tag with the specified name.

  4. git fetch - Retrieves the latest changes from the remote repository without merging them.