Setting Up and Configuring Git

Setting Up and Configuring Git

  1. Initialize a Git repository:
git init
  1. Clone a repository:
git clone <repository_url>
  1. Configure user information:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Working with Local Repositories

  1. Check the status of the repository:
git status
  1. Add files to the staging area:
git add <file_name>
git add .
  1. Commit changes:
git commit -m "Commit message"
  1. View commit history:
git log

Working with Remote Repositories

  1. Add a remote repository:
git remote add origin <repository_url>
  1. Push changes to a remote repository:
git push origin <branch_name>
  1. Pull changes from a remote repository:
git pull origin <branch_name>
  1. Fetch changes from a remote repository:
git fetch

Branching and Merging

  1. Create a new branch:
git branch <branch_name>
  1. Switch to a branch:
git checkout <branch_name>
  1. Create and switch to a new branch:
git checkout -b <branch_name>
  1. Merge a branch into the current branch:
git merge <branch_name>
  1. Delete a branch:
git branch -d <branch_name>

Stashing Changes

  1. Stash changes:
git stash
  1. Apply stashed changes:
git stash apply

Additional Useful Commands

  1. Show changes between commits, commit and working tree, etc.:
git diff
  1. Revert changes:
git revert <commit_id>
  1. Reset current HEAD to the specified state:
git reset <commit_id>

These commands should cover most of the basic and intermediate tasks you’ll encounter while using GitHub

Leave a comment

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