top of page

Version Control with Git

Part 1: Create Your First Git Repository

Purpose: Learn how Git tracks changes locally — the first step in version control.


Steps

  1. Create a folder

    ree

    You created a project directory to store your code.

  2. Initialize Git

    git init

    ree

    This turns your folder into a Git repository (Git starts tracking changes here).

  3. Create a file

    echo "Hello Git" > hello.txt


    You made your first file to track.

  4. Check the status

    git status


    Git shows that hello.txt is untracked.

  5. Add the file to staging

    git add hello.txt

    ree

    This prepares the file for commit (snapshot).

  6. Commit your changes


    git commit -m "Initial commit: added hello.txt"

    ree

    Congratulations!!! You’ve saved your first version — a snapshot of the file.

Git records your work in small “commits” that you can track or roll back later.


Part 2: Track File Changes and View History

Purpose: Understand how Git saves different versions of your files.

Steps

  1. Edit the file

    echo "This is my second line." >> hello.txt


  2. Check the difference

    git diff

    ree

    Shows what changed since the last commit.

  3. Stage and commit again

    git add hello.txt


    git commit -m "Added a second line to hello.txt"

    ree
  4. View commit history

    git log --oneline

    ree

    See the list of all versions you’ve saved.


Lesson Learned:Git keeps a complete timeline of your work — you can see, compare, or restore any version anytime.


Part 3: Work with Branches

Purpose: Learn how to work on new features safely without disturbing the main code.

Steps

  1. Create and switch to a new branch


    git checkout -b feature-update

ree
  1. Edit the file

    echo "New feature: Git branching!" >> hello.txt


  2. Commit the change

    git add hello.txt

    git commit -m "Added feature update message"

    ree

  3. Switch back to main branch

    git checkout master

    ree

  4. Compare branches

    git diff feature-update

ree


Lesson Learned:Branches let you experiment or develop features independently — and merge them later when ready.

Part 4: Merge Changes

Purpose: Understand how to combine your work from multiple branches.

Steps


  1. Merge feature branch into main

    git merge feature-update

    Git combines the feature branch changes into main.

    ree

  2. Check the merged file

    type hello.txt

    ree


Part 5: Connect with GitHub and Push Code

Purpose: Learn to upload your local project to GitHub and collaborate online.

Steps

  1. Create a new repo on GitHub

    Go to GitHub → “New Repository” → Name it git-demo

    Don’t add README yet.


  2. Connect local Git to GitHub

    git remote add origin https://github.com/<your-username>/git-demo.git

  3. Push your code

    git branch -M master

    git push -u origin master

ree
  1. Check your GitHub accountYour code is now visible online.

    ree

    Lesson Learned:Git + GitHub = version control + cloud collaboration.You can now share your code, work with teams, and track contributions.


$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

$50

Product Title

Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

Recommended Products For This Post
 
 
 

Recent Posts

See All
Containerization

Docker Zoo to understand containerization Run 3 tiny web apps (Cat, Dog, Cow) in separate containers  and see how containerization isolates them. Folder setup Create a folder for your project: md dock

 
 
 

Comments


© 2023 by newittrendzzz.com 

  • Facebook
  • Twitter
  • Instagram
bottom of page