Skip to content

Instantly share code, notes, and snippets.

@jonahgeek
Created September 25, 2023 03:20
Show Gist options
  • Save jonahgeek/d6a3abeccc97a8a1b25a31a314e05c48 to your computer and use it in GitHub Desktop.
Save jonahgeek/d6a3abeccc97a8a1b25a31a314e05c48 to your computer and use it in GitHub Desktop.
Getting started with git and github

Getting Started with Git and GitHub

Git is a powerful distributed version control system that allows you to track changes in your code and collaborate with others. GitHub is a popular platform for hosting and sharing Git repositories. This guide will help you get started with Git and GitHub.

Prerequisites

  1. Install Git: If you haven't already, download and install Git for your operating system.

  2. Create a GitHub Account: If you don't have a GitHub account, sign up for one.

Configuring Git

Before you start using Git, configure your identity:

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Replace "Your Name" and "[email protected]" with your name and email.

Creating a Git Repository

  1. Initialize a New Repository: Open your terminal and navigate to the project folder. Use the following command to create a new Git repository:
$ git init
  1. Add Files: Add the files you want to track to the repository using the following command:
$ git add .
  1. Commit Changes: Commit your changes with a meaningful message:
$ git commit -m "Initial commit"

Working with GitHub

  1. Create a Repository on GitHub:

    • Log in to your GitHub account.
    • Click the "+" icon in the top right corner and select "New Repository."
    • Follow the instructions to create a new repository.
  2. Link Your Local Repository to GitHub:

    • Use the following commands to link your local repository to the remote GitHub repository:
$ git remote add origin <repository-url>
$ git branch -M main
$ git push -u origin main

Replace <repository-url> with the URL of your GitHub repository.

  1. Push Changes to GitHub:
    • After making changes locally, commit them and push to GitHub:
$ git add .
$ git commit -m "Update something"
$ git push origin main

Cloning a Repository

  1. Clone a Repository: To clone a repository from GitHub to your local machine, use the following command:
$ git clone <repository-url>

Replace <repository-url> with the URL of the GitHub repository you want to clone.

Branching and Pull Requests

  1. Create a New Branch: To work on a new feature or fix, create a new branch:
$ git checkout -b new-feature
  1. Make Changes and Commit: Make your changes, commit them, and push the branch to GitHub:
$ git add .
$ git commit -m "Implement new feature"
$ git push origin new-feature
  1. Create a Pull Request: Go to your GitHub repository, switch to the new branch, and create a pull request to merge your changes into the main branch.

Additional Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment