Logo

dev-resources.site

for different kinds of informations.

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

Published at
12/21/2024
Categories
git
github
cloudcomputing
devops
Author
Oluwatobiloba Akinbobola
Categories
4 categories in total
git
open
github
open
cloudcomputing
open
devops
open
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 "[email protected]"

3.Verify Installation:
Check the installed Git version:

   git --version

Creating a Repository

Local Repository

1.Navigate to your project folder:

   cd /path/to/your/project

folder
2.Initialize a Git repository:

   git init

3.Add files to the repository:

   git add .

4.Commit the changes:

   git commit -m "Initial commit"

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

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

Making Commits

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

   git add <file-name>

Or stage all changes:

   git add .

2.Commit Changes: Save changes to the repository:

   git commit -m "Your commit message"

commit changes

commit

Pushing Changes to GitHub

Send your commits to the remote repository:

git push origin main

Pulling Changes from GitHub

Fetch and merge changes from the remote repository:

git pull origin main

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.

Featured ones: