Setting Up and Configuring Git
- Initialize a Git repository:
git init
- Clone a repository:
git clone <repository_url>
- Configure user information:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
Working with Local Repositories
- Check the status of the repository:
git status
- Add files to the staging area:
git add <file_name> git add .
- Commit changes:
git commit -m "Commit message"
- View commit history:
git log
Working with Remote Repositories
- Add a remote repository:
git remote add origin <repository_url>
- Push changes to a remote repository:
git push origin <branch_name>
- Pull changes from a remote repository:
git pull origin <branch_name>
- Fetch changes from a remote repository:
git fetch
Branching and Merging
- Create a new branch:
git branch <branch_name>
- Switch to a branch:
git checkout <branch_name>
- Create and switch to a new branch:
git checkout -b <branch_name>
- Merge a branch into the current branch:
git merge <branch_name>
- Delete a branch:
git branch -d <branch_name>
Stashing Changes
- Stash changes:
git stash
- Apply stashed changes:
git stash apply
Additional Useful Commands
- Show changes between commits, commit and working tree, etc.:
git diff
- Revert changes:
git revert <commit_id>
- 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