Skip to content

musjib999/swe4209

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Git Class: Working with git and github

This a documentation on how to create a new Git repository, add files, and push your code to a remote repository on GitHub.

Prerequisites

Before you begin, ensure that:

  • Git is installed on your machine.
  • You have a GitHub account.
  • You have access to a terminal or command line interface.

Step 1: Create a New Git Repository

  1. Navigate to your project directory
    Open your terminal and navigate to the directory where you want to initialize your Git repository.

    cd /path/to/your/project
  2. Initialize the Git repository
    Initialize a new Git repository in your project directory.

    git init

    This command creates a new .git subdirectory in your project folder, which will track all your version-controlled files.

Step 2: Add Files to the Repository

  1. Check the status of your repository
    See which files are untracked or have changes that need to be committed.

    git status
  2. Add files to the staging area
    Add all files in your project directory to the staging area to prepare them for commit.

    git add .

    Alternatively, you can add specific files:

    git add filename1 filename2

Step 3: Commit Your Changes

  1. Commit the staged files
    Commit your changes with a descriptive message to record the snapshot of your project at this point.

    git commit -m "Initial commit"

Step 4: Push Code to GitHub

  1. Create a new repository on GitHub
    Go to GitHub, create a new repository, and copy the repository URL.

  2. Add the remote repository
    Link your local repository to the remote repository on GitHub.

    git remote add origin https://github.com/your-username/your-repo-name.git
  3. Push your code to the remote repository
    Push the code in your local repository to the remote repository on GitHub.

    git push -u origin master

    The -u flag sets the origin repository as the default remote for future pushes.

Git Class: Other things you can do with git

This part covers essential Git operations, including cloning a repository, making changes, pulling the latest code, forking a repository, and creating a pull request.

Step 1: Clone a Repository

  1. Find the repository URL
    Navigate to the repository on GitHub you want to clone. Click the "Code" button and copy the repository URL (HTTPS, SSH, or GitHub CLI).

  2. Clone the repository
    Open your terminal and use the git clone command to clone the repository to your local machine.

    git clone https://github.com/username/repository-name.git
  3. Navigate into the repository
    Change into the newly created directory.

    cd repository-name

Step 2: Make Changes and Commit

  1. Create a new branch
    It's a good practice to create a new branch before making changes. This keeps your changes isolated from the main branch.

    git checkout -b feature-branch-name

    Replace feature-branch-name with a meaningful name describing your feature or change.

  2. Make your changes
    Modify the files as needed using your favorite text editor or IDE.

  3. Add changes to the staging area
    Add the modified files to the staging area.

    git add .
  4. Commit your changes
    Commit the staged changes with a descriptive commit message.

    git commit -m "Description of changes made"

Step 3: Pull the Latest Code

  1. Switch to the main branch
    Before pulling the latest code, switch to the main branch (usually main).

    git checkout main
  2. Pull the latest code
    Pull the latest changes from the remote repository to ensure your local repository is up-to-date.

    git pull origin main
  3. Merge your changes
    Merge your feature branch into the main branch.

    git merge feature-branch-name

Step 4: Fork a Repository and Create a Pull Request

  1. Fork the repository
    Navigate to the repository on GitHub and click the "Fork" button. This creates a copy of the repository under your GitHub account.

  2. Clone your fork
    Clone your forked repository to your local machine.

    git clone https://github.com/your-username/forked-repo-name.git

    Replace https://github.com/your-username/forked-repo-name.git with the URL of your forked repository.

  3. Make your changes
    Follow the same steps as mentioned earlier to create a new branch, make changes, add, commit, and push the changes.

  4. Push your branch to GitHub
    Push your branch to your forked repository on GitHub.

    git push origin feature-branch-name
  5. Create a pull request

    • Go to the original repository (not your fork).
    • You will see a prompt to create a pull request from your recently pushed branch.
    • Click "Compare & pull request."
    • Add a title and description for your pull request.
    • Submit the pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages