DEV Community

Cover image for Your First Commit: A Beginner’s Journey with Git and GitHub
Oluwatobiloba Akinbobola
Oluwatobiloba Akinbobola

Posted on

Your First Commit: A Beginner’s Journey with Git and GitHub

Introduction

Git and GitHub are two crucial tools for contemporary software development that are explained in this article for both novice and seasoned engineers. Git is a distributed version control system that monitors codebase changes, facilitating effective code history management and collaboration. By making repositories available online, GitHub, a web-based platform that leverages Git for version control and provides services like issue tracking, project management, and code hosting, streamlines collaboration.

Setting Up Git

1.Install Git:

  • Windows: Download and install Git from git-scm.com.
  • macOS: Use Homebrew:

     brew install git
    
  • Linux: Use your package manager:

     sudo apt-get install git
    

2.Configure Git: (using window OS)
Set your username and email to identify your commits:

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

3.Verify Installation:
Check the installed Git version:

   git --version
Enter fullscreen mode Exit fullscreen mode

Creating a Repository

Local Repository

1.Navigate to your project folder:

   cd /path/to/your/project
Enter fullscreen mode Exit fullscreen mode

folder
2.Initialize a Git repository:

   git init
Enter fullscreen mode Exit fullscreen mode

3.Add files to the repository:

   git add .
Enter fullscreen mode Exit fullscreen mode

4.Commit the changes:

   git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Folder created

Remote Repository

1.Create a repository on GitHub:
repository

  • Log in to your GitHub account.
  • Click the "+" icon and select "New repository."
  • Name your repository and click "Create repository." Repository

2.Link your local repository to GitHub:

   git remote add origin https://github.com/yourusername/your-repository.git
Enter fullscreen mode Exit fullscreen mode

link repo

  • Create nano readme.md Nano
  • Save nano file save nano
  • cat readme.md and git add readme.md cat read me
  • Sign in with your browser sign in
  • Authorize git-ecosystem Authorize 3.Push your local repository to GitHub:
   git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Making Commits

1.Stage Changes: Add modified files to the staging area:

   git add <file-name>
Enter fullscreen mode Exit fullscreen mode

Or stage all changes:

   git add .
Enter fullscreen mode Exit fullscreen mode

2.Commit Changes: Save changes to the repository:

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

commit changes

commit

Pushing Changes to GitHub

Send your commits to the remote repository:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Pulling Changes from GitHub

Fetch and merge changes from the remote repository:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

edit read me

Best Practices

  1. Write clear and descriptive commit messages.
  2. Regularly pull changes to stay updated.
  3. Use branches for features and bug fixes.
  4. Push frequently to avoid losing work.

Top comments (0)