GitHub Cheat Sheet

Below is a cheat sheet for some common GitHub commands and actions:

Basic Git Commands

Initialize a Repository:

git init

Clone a Repository:

git clone repository_url

Check Repository Status:

git status

Add Changes to Staging Area:

git add .

Commit Changes:

git commit -m "Commit message"

Pull Changes from Remote Repository:

git pull origin branch_name

Push Changes to Remote Repository:

git push origin branch_name

Branching

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 new_branch_name

Merge Branch into Current Branch:

git merge branch_name

Delete a Branch:

git branch -d branch_name

Remote Repository

Add a Remote Repository:

git remote add origin repository_url

View Remote Repositories:

git remote -v

Undo Changes

Discard Changes in Working Directory:

git checkout -- file_name

Discard Changes in Staging Area:

git reset file_name

Undo Last Commit (Local):

git reset HEAD~1

Undo Last Commit (Remote):

git push origin HEAD --force

GitHub Pull Requests

Create a Pull Request:

  • Create a new branch, push changes, then go to the repository on GitHub and click “Compare & pull request.”

Review and Merge a Pull Request:

  • Review changes, leave comments, and merge the pull request on GitHub.

Git Tags

Create a Tag:

git tag tag_name

List Tags:

git tag

Push Tags to Remote Repository:

git push origin tag_name

GitHub Actions

Create a Workflow File:

  • Create a .github/workflows/workflow_name.yml file.

Git Ignore

Ignore Files:

  • Create a .gitignore file and list files/directories to be ignored.

GitHub Wiki

Create Wiki Pages:

  • Navigate to the repository on GitHub, go to the “Wiki” tab, and create/edit pages.

GitHub Issues

Create an Issue:

  • Go to the “Issues” tab on GitHub and create a new issue.

This cheat sheet covers some essential Git and GitHub commands. For more detailed information and advanced features, refer to the GitHub documentation.