GIT Cheat Sheat

Here’s a usage cheat sheet for Git, covering basic to advanced usage:

Basic Usage:

  1. Initialize a Repository:
   git init
  1. Clone a Repository:
   git clone <repository_url>
  1. Check Status of Repository:
   git status
  1. Add Changes to Staging Area:
   git add <file_name>
  1. Commit Changes:
   git commit -m "Commit message"
  1. Push Changes to Remote Repository:
   git push origin <branch_name>
  1. Pull Changes from Remote Repository:
   git pull origin <branch_name>
  1. Create a New Branch:
   git checkout -b <new_branch_name>
  1. Switch to an Existing Branch:
   git checkout <branch_name>
  1. Merge Branches:
    git merge <branch_name>

Advanced Usage:

  1. View Commit History:
   git log
  1. View Changes in Commit:
   git show <commit_hash>
  1. Undo Changes in Working Directory:
   git checkout -- <file_name>
  1. Reset Staging Area to Previous Commit:
   git reset HEAD <file_name>
  1. Amend Last Commit:
   git commit --amend
  1. Stash Changes:
   git stash
  1. Apply Stashed Changes:
   git stash apply
  1. Interactive Rebase:
   git rebase -i <commit_hash>
  1. Cherry-pick Commits:
   git cherry-pick <commit_hash>
  1. View Remote URLs: git remote -v
  2. Add Remote Repository: git remote add <remote_name> <repository_url>
  3. Remove Remote Repository:
    git remote remove <remote_name>

Remember, Git is a powerful version control system, and mastering its various commands and workflows can greatly enhance your ability to manage and collaborate on software projects. Practice and experimentation are key to becoming proficient with Git.