Git and GitHub – How to start with Git (Part -3)

1. Create a Repository (repo)

A repository is a storage location where your project files and their version history are kept.

Steps:

  • Open Git Bash.
  • Navigate to the directory where you want to create the repository.
  • Run the following command to initialize a new Git repository:
git init

Example:

mkdir my_project
cd my_project
git init

This creates a new directory called my_project, navigates into it, and initializes an empty Git repository.

.git file is hidden file to see it , enable the hidden item from view section

2. Write Your Code

Create or add the files for your project. You can use any text editor or IDE to write your code.

Example:

  • Create a new file named main.py and write some Python code in it.
# main.py
print("Hello, Git!")

or

3. Add a File to Git

To start tracking a file with Git, you need to add it to the staging area using the git add command.

Steps:

  • Use the following command to add a file to the staging area:
git add <filename>

Example:

git add main.py

This command stages the main.py file, telling Git to include it in the next commit.

4. Commit a File to Git

A commit saves the current state of the files in the staging area to the repository. Each commit has a unique ID and an associated message describing the changes.

Steps:

  • Use the following command to commit the staged files:
git commit -m "Your commit message"

Example:

git commit -m "Add main.py with a simple hello world script"

his command commits the main.py file with the message “Add main.py with a simple hello world script”.

Check Git config list

$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.email=jami.cotocus@gmail.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
user.name=Jami Raj
user.email=jami.cotocus@gmail.com

Summary of the Steps with Full Example

Create a repository:

    mkdir my_project
    cd my_project
    git init
    

    Write your code:

    • Create a file main.py and add the following code
    print("Hello, Git!")
    

    Add a file to Git:

    git add main.py
    

    Commit a file to Git:

    git commit -m "Add main.py with a simple hello world script"
    

    Command History

    git init
    touch file2.java
    touch file3.java
    git add file1.java
    git config user.name "Jami Raj"
    git config user.email "jami.cotocus@gmail.com"
    git config --list
    git commit -m"Adding first commit"
    
    

    Related Posts

    Git and GitHub – GitHub Overview (Part-15)

    1. Github Description: 2. Org (Organization) Description: Example: 3. Team Description: Example: 4. Auth (Authentication) Description: Examples: OAuth Authentication: Personal Access Tokens: SSH Key Authentication: 5. Action…

    Read More

    Git and GitHub – Git Log Explanation (Part-14)

    Git Log Explanation Explanation of Each Part 1. Commit Hash 2. References (Branches and Tags) 3. Commit Message Simplified Breakdown of Each Line Summary The git log…

    Read More

    Git and GitHub – Merge and Pull (Part-13)

    Merge and Pull in Git Merge Merge is a command used to combine the changes from one branch into another. It is typically used to integrate changes…

    Read More

    Git and GitHub – Types of branch (Part-12)

    Local and Remote Branches in Git Local Branch A local branch is a branch that exists in your local Git repository. You create and manage local branches…

    Read More

    Git and GitHub – Git Undoing, Conflict Resolution, Cherry Picking, Stash (Part-11)

    Undoing changes in Git can be approached in several ways, depending on what you need to achieve. Here, we’ll cover the most common scenarios and commands for…

    Read More

    Git and GitHub – Understanding Git Concepts (Part-10)

    Understanding Git Concepts 1. Git Branching and Merging Branching allows you to create a separate line of development. It’s useful for working on different features or fixes…

    Read More
    guest
    0 Comments
    Oldest
    Newest Most Voted
    0
    Would love your thoughts, please comment.x
    ()
    x