DEV Community

Cover image for Getting Started with GitHub
Vidyarathna Bhat
Vidyarathna Bhat

Posted on

Getting Started with GitHub

Hey there!
I'm sharing an easy-to-follow introduction to GitHub, a popular platform that simplifies code management and collaboration. Whether you're new to coding or just new to GitHub, this post will cover the basics you need to know to get started.

What is GitHub?

GitHub is a platform that allows developers to host and review code, manage projects, and collaborate with others. It integrates Git, a distributed version control system created by Linus Torvalds, the creator of Linux. GitHub provides a web-based interface to Git, making it easier for teams to work together on code.

Why Use GitHub?

  1. Version Control: Keep track of changes in your code over time.
  2. Collaboration: Work with others on projects, no matter where they are.
  3. Backup: Your code is stored in the cloud, safe from local data loss.
  4. Showcase: Display your projects to potential employers or collaborators.

Getting Started

1. Create a GitHub Account

  • Visit GitHub and sign up for an account.
  • Choose a username, provide an email address, and set a password.
  • Verify your email to activate your account.

2. Install Git

Before you can use GitHub, you need to install Git on your local machine.

  • Windows: Download Git from the official website and follow the installation instructions.
  • Mac: Use Homebrew: brew install git.
  • Linux: Use the package manager: sudo apt-get install git.

3. Set Up Git

After installing Git, configure it with your GitHub username and email.

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Enter fullscreen mode Exit fullscreen mode

4. Create a Repository

A repository (or repo) is where your project's files and revision history are stored.

  • On GitHub, click the + icon in the upper-right corner and select New repository.
  • Fill in the repository name, description (optional), and choose whether it will be public or private.
  • Click Create repository.

5. Clone the Repository

To work on your project locally, you need to clone the repository.

  • Navigate to your repository on GitHub.
  • Click the Code button and copy the URL.
  • In your terminal, use the git clone command:
git clone https://github.com/your-username/your-repository.git
Enter fullscreen mode Exit fullscreen mode

6. Make Changes and Commit

After cloning your repository, navigate to its directory:

cd your-repository
Enter fullscreen mode Exit fullscreen mode

Create or edit files as needed. Once you're ready to save your changes, add them to the staging area and commit:

git add .
git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode

7. Push Changes to GitHub

To upload your changes to GitHub, use the git push command:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Replace main with the name of your branch if it's different.

8. Branching and Merging

Branching allows you to work on different features or fixes separately. To create a new branch:

git checkout -b new-feature
Enter fullscreen mode Exit fullscreen mode

Switch back to the main branch and merge your changes:

git checkout main
git merge new-feature
Enter fullscreen mode Exit fullscreen mode

9. Pull Requests

When collaborating, you might want to review changes before merging them. This is done through pull requests (PRs).

  • Push your branch to GitHub.
  • Go to your repository on GitHub and click New pull request.
  • Review the changes and click Create pull request.

Happy coding!

Top comments (1)

Collapse
 
shreeprabha_bhat profile image
Shreeprabha bhat

Informative one for beginners