0% found this document useful (0 votes)
21 views3 pages

1 Git

The document outlines basic Git commands for setting up a repository and managing files. Key commands include 'git init' to create a repository, 'git add' to stage files, 'git commit' to save changes, and 'git log' to view commit history. Each command is accompanied by examples and explanations of their outputs.

Uploaded by

sonamv7022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

1 Git

The document outlines basic Git commands for setting up a repository and managing files. Key commands include 'git init' to create a repository, 'git add' to stage files, 'git commit' to save changes, and 'git log' to view commit history. Each command is accompanied by examples and explanations of their outputs.

Uploaded by

sonamv7022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 1:

Setting Up and Basic Commands

Initialize a new Git repository in a directory. Create a new file and add it to the
staging area and commit the changes with an appropriate commit message

 git --version → check Git version


 git init → create a repository
 git status → check what’s changed/staged
 git add → move changes to staging
 git commit -m → save changes with message
 git log → view history of commits

1. git --version

Checks the version of Git installed on your system.

 Example:
 git --version

Output:

git version 2.44.0

 Useful for confirming Git is installed and knowing which version you’re running.

2. git init

Initializes a new Git repository in your current directory.

 Example:
 git init

Output:

Initialized empty Git repository in /home/user/project/.git/

 This creates a hidden .git/ folder where Git stores all its tracking information.

3. git status

Shows the state of your working directory and staging area.

 Example (after creating [Link]):


 git status
Output:

Untracked files:
(use "git add <file>..." to include in what will be committed)
[Link]

 This tells you:


o Which files are untracked (new).
o Which files are staged for commit.
o Which files are modified but not staged.

4. git add <file names>

Adds files to the staging area (Index).

 Example:
 git add [Link] [Link]
 Now these files are staged → meaning they’re prepared to be committed.
 You can also add all files at once:
 git add .

5. git commit -m "commit message"

Saves staged changes into the repository history with a message.

 Example:
 git commit -m "Add file1 and file2 with initial content"

Output:

[main (root-commit) 6f2c9a1] Add file1 and file2 with initial content
2 files changed, 10 insertions(+)
create mode 100644 [Link]
create mode 100644 [Link]

 Each commit gets a unique ID (hash) and becomes part of your project’s history.
 The message should explain what and why you committed.

6. git log

Shows the commit history.

 Example:
 git log

Output:

commit 6f2c9a1a3a3e4f23cfa0bcdcb17f57d9f0a1a89d (HEAD -> main)


Author: Alice <alice@[Link]>
Date: Mon Sep 29 10:15:42 2025 +0530

Add file1 and file2 with initial content

 This shows:
o Commit ID (hash).
o Branch (e.g., main).
o Author.
o Date/time.
o Commit message.

You might also like