Github

A Fun way to learn Github

Let's get serious about this GitHub journey and leave no stone unturned.


Setting Up GitHub CLI

Chapter 1: Initialize & Clone

  • Creating a New Repository

    • Go to GitHub.

    • Click the '+' icon > 'New repository'.

    • Name it "DevMasterpiece".

    • Select 'Private/Public'.

    • Initialize with a README.

    • Click 'Create repository'.

  • Cloning an Existing Repository

    • In your terminal, navigate to your desired directory.

    • Run: git clone https://github.com/YourUsername/DevMasterpiece.git


Chapter 2: Commits & Changes

  • The Staging Area

    • Edit README.md.

    • Stage your changes: git add README.md or git add . to stage all changes.

  • Committing Changes

    • Run: git commit -m "Descriptive message about changes"


Chapter 3: Pushing & Pulling

  • Pushing Changes

    • To push to the main branch: git push origin master

    • To push to a different branch: git push origin branch-name

  • Pulling Updates

    • Sync with the latest: git pull origin master or for a different branch: git pull origin branch-name


Chapter 4: Branching & Merging

  • Creating & Switching Branches

    • Create and switch to a new branch: git checkout -b "branch-name"

    • Simply switch between branches: git checkout branch-name

  • Pushing Branches

    • Push your new branch: git push -u origin branch-name

    • The -u sets the upstream, making subsequent pushes simpler.

  • Merging Branches

    • Switch to the target branch (commonly master): git checkout master

    • Merge your branch: git merge branch-name


Chapter 5: Pull Requests

  • Creating a Pull Request

    • Push your branch to GitHub using: git push -u origin branch-name

    • On GitHub, navigate to the main page of the repo.

    • Click the 'Pull request' tab > "New Pull Request".

    • Select your branch from the dropdown.

    • Click "Create pull request".

    • Add any additional details and click "Submit pull request".

  • Reviewing & Merging a Pull Request

    • Navigate to the 'Pull requests' tab on GitHub.

    • Click on the PR you want to review.

    • After reviewing, click "Merge pull request" > "Confirm merge".

    • Optionally, delete the branch after merging.


Chapter 6: Authentication Tokens

  • Generating a Token

    • Go to Settings > Developer settings > Personal access tokens on GitHub.

    • Click "Generate new token".

    • Save the token securely.

  • Using Tokens

    • Use the token when prompted for a password in the terminal.


Chapter 7: Pro Tips & Advanced Commands

  • Stashing Changes

    • Hide current changes: git stash

    • Reapply stashed changes: git stash pop

  • Remotes

    • View connected remote repositories: git remote -v

    • Add a new remote repo: git remote add remoteName repoURL

  • Rebase

    • Apply changes from one branch onto another: git rebase branch-name

    • This rewrites commit history. Ensure you understand its implications.

  • Checking History

    • View commit history: git log

    • For a cleaner history view: git log --oneline

  • Undoing Things

    • Amend the last commit (e.g., to fix a commit message): git commit --amend

    • Reset your branch to look exactly like another branch: git reset --hard branch-name


This guide is meant to offer a comprehensive look into the daily workings of GitHub. Remember: while these commands provide power, they also come with responsibility. Always double-check your commands, especially when rebasing or resetting, as they can change commit history. Dive deep, practice, and may your repositories always be conflict-free! ALSOOO Follow me on X (Twitter) for more developer tips!

Last updated