Here’s a list of useful GitHub command-line (Git) commands with descriptions:
Basic Git Commands
git init
Initializes a new Git repository in the current directory.
git clone <repo_url>
Clones a remote repository to your local machine.
git status
Displays the current state of your working directory and staging area.
git add <file>
Adds a file to the staging area.
git add .
Stages all changes (new, modified, deleted files).
git commit -m "Commit message"
Commits staged changes with a message.
git commit --amend -m "New message"
Modifies the last commit message.
Branching & Merging
git branch
Lists all branches in the repository.
git branch <branch_name>
Creates a new branch.
git checkout <branch_name>
Switches to an existing branch.
git switch <branch_name>
Another way to switch to a branch.
git checkout -b <branch_name>
Creates and switches to a new branch.
git merge <branch_name>
Merges the specified branch into the current branch.
git rebase <branch_name>
Moves the base of your branch to the latest commit of the specified branch.
Working with Remote Repositories
git remote -v
Lists the remote repositories.
git remote add origin <repo_url>
Adds a remote repository.
git push -u origin <branch_name>
Pushes a branch to a remote repository and sets it as the upstream branch.
git push origin --delete <branch_name>
Deletes a remote branch.
git fetch origin
Fetches updates from the remote repository without merging.
git pull origin <branch_name>
Fetches and merges updates from a remote branch.
git push origin <branch_name>
Pushes local commits to a remote branch.
Undoing Changes
git reset --soft HEAD~1
Moves the last commit back to the staging area.
git reset --hard HEAD~1
Completely removes the last commit.
git checkout -- <file>
Discards changes in the working directory.
git restore <file>
Another way to discard changes.
git revert <commit_hash>
Creates a new commit that undoes the changes from a previous commit.
Viewing History
git log
Shows commit history.
git log --oneline --graph --all
Displays a compact commit history with branches.
git diff
Shows differences between files in working directory and staging area.
git diff --staged
Shows differences between staged files and the last commit.
Stashing Changes
git stash
Saves uncommitted changes for later use.
git stash pop
Restores the last stashed changes and removes them from the stash.
git stash list
Shows a list of stashed changes.
git stash drop
Deletes the most recent stash.
Tagging
git tag <tag_name>
Creates a new tag at the current commit.
git tag -a <tag_name> -m "Tag message"
Creates an annotated tag.
git push origin <tag_name>
Pushes a tag to a remote repository.
git push --tags
Pushes all local tags to the remote repository.
GitHub Specific Commands
gh auth login
Logs in to GitHub via the CLI.
gh repo clone <repo_name>
Clones a GitHub repository.
gh pr create
Creates a pull request from the CLI.
gh pr list
Lists pull requests for the repository.
gh issue list
Lists issues in the repository.
gh repo view
Shows details about the repository.
Would you like me to include more advanced Git commands? 🚀