Skip to content
Pankaj Chouhan edited this page May 31, 2024 · 1 revision

Welcome to the C-Programming-Tutorial-codeswithpankaj wiki!

Step-by-step tutorial to get you started with Git:

Step 1: Install Git

  • Windows: Download and install Git from git-scm.com.
  • Mac: Install Git using Homebrew: brew install git.
  • Linux: Use your package manager, for example: sudo apt-get install git.

Step 2: Configure Git

Open your terminal and set your username and email:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Step 3: Create a Local Repository

  1. Create a new directory for your project:
    mkdir my_project
    cd my_project
  2. Initialize a Git repository:
    git init

Step 4: Add Files and Make Your First Commit

  1. Create a new file:
    echo "Hello, Git!" > hello.txt
  2. Check the status of your repository:
    git status
  3. Add the file to the staging area:
    git add hello.txt
  4. Commit the file:
    git commit -m "Add hello.txt with a greeting message"

Step 5: Connect to a Remote Repository (GitHub)

  1. Go to GitHub and create a new repository (don't initialize it with a README).
  2. Connect your local repository to GitHub:
    git remote add origin https://github.com/yourusername/your-repo-name.git

Step 6: Push Changes to GitHub

  1. Push your commits to the remote repository:
    git push -u origin master

Step 7: Making Changes and Updating the Repository

  1. Make changes to your file:
    echo "Adding more content" >> hello.txt
  2. Check the status and see the changes:
    git status
  3. Add and commit the changes:
    git add hello.txt
    git commit -m "Update hello.txt with additional content"
  4. Push the changes to GitHub:
    git push

Step 8: Working with Branches

  1. Create a new branch:
    git branch new-feature
  2. Switch to the new branch:
    git checkout new-feature
  3. Make changes and commit them in the new branch:
    echo "This is a new feature" > feature.txt
    git add feature.txt
    git commit -m "Add new feature"
  4. Push the new branch to GitHub:
    git push -u origin new-feature

Step 9: Merging Branches

  1. Switch back to the master branch:
    git checkout master
  2. Merge the new branch into the master branch:
    git merge new-feature
  3. Push the changes to GitHub:
    git push

Step 10: Cloning a Repository

  1. Clone a repository from GitHub:
    git clone https://github.com/username/repo-name.git

This is a basic overview to get you started with Git. As you become more comfortable, you'll learn more advanced features and workflows.