0% found this document useful (0 votes)
4 views

GitHub Learn final content (1)

This document provides an overview of basic Git commands and concepts, including version control systems, Git configuration, and repository management. It covers how to initialize a repository, track changes, commit files, and manage branches. Additionally, it explains the differences between Git and GitHub, as well as how to clone repositories and work with tags.

Uploaded by

Sakthi Vel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

GitHub Learn final content (1)

This document provides an overview of basic Git commands and concepts, including version control systems, Git configuration, and repository management. It covers how to initialize a repository, track changes, commit files, and manage branches. Additionally, it explains the differences between Git and GitHub, as well as how to clone repositories and work with tags.

Uploaded by

Sakthi Vel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CHAPTER 1(BASIC GIT COMMANDS)

GIT (Distributed Version Control System)

1. Version Control:
-Version control allows you to track and manage changes to files over time.
-Every time you make an update or add a new file, a new version is created.
-Importantly, this system doesn't modify older files.
-Instead, it stores the changes in a new version, preserving previous versions of your
code for future reference.

2. Types of Version Control Systems:

i. Local Version Control System:


-In a local version control system, all changes are made and saved on your local
machine.
-You can work with different versions of your code, but everything happens locally
without needing any external system.

ii. Centralized Version Control System (CVCS):


-Centralized version control systems rely on a remote server for access and storage.
-To make changes, you must first retrieve the code from the central repository, edit it
on your local machine, and then push the changes back to the central server.
-The server serves as the "single source of truth" for all project versions.

iii. Distributed Version Control System (DVCS):


-A distributed version control system (like Git) provides you with a local copy of the
entire repository, including the complete history of commits.
-You can make changes offline, work with branches, and merge changes when
ready.
-This system allows greater flexibility, as every contributor has their own local
repository with the full project history.

3.Setting Up Git Configuration:


Step 1: Set Your Username To configure Git with your username, run the following
command in your terminal:

git config --global user.name "snagendran"

This sets your username as "snagendran" for all your future commits.
Step 2: Set Your Email Next:set your email address, which is associated with your Git
commits. Run the following command:

git config --global user.email "mypass"

Replace "mypass" with your actual email address.

Step 3: List Git Configuration To verify the configuration you've set, you can list all your
global Git settings:

git config --global –list

This will display the username, email, and other configurations you've set globally in Git.
PRACTICAL REF
ONCE DONE GIT WAS CREATED BY OWN

4. Commit History:
Commit: Every time you make changes and save them in Git, it creates a new version of
your project.
Staging Area: Before committing, your changes are placed in a "staging area." This area lets
you review and organize which changes you want to commit.
Each commit captures the state of the project at a particular moment in time, allowing you
to track the evolution of your project.

5.Creating a Local Repository:


To start using Git in a project, you need to initialize a repository on your local machine. This
is done by running:

git init

git init: This command creates an empty Git repository in your project folder. Once this is
done, you can start tracking your files and making commits.
6. Git Status:
Once you've created a Git repository, you can track the status of your project with the
following command:

git status

git status: This command shows the current state of your working directory and staging
area.
It will tell you:
-Which files have been modified.
-Which files are staged and ready for committing.
-Which files are untracked (i.e., new files not yet added to Git).

7. Switching from Master to Main Branch:


By default, when you initialize a Git repository, the primary branch is often called master. If
you want to rename it to main (a more modern convention), you can do this using the
following command:

git init -b main

git init -b main: This command initializes a new Git repository and sets the default branch
name to main instead of master.

8. How to Add a File to Git:

Step 1: Create a File First, create a new file in your working directory. For example, you can
create a simple text file like Firstcode.txt (this could be a Java, C, C++, or any other type of
file).

Step 2: Check the Status Next, check the status of your Git repository by running:

git status

-git status will show you the current state of your working directory.
-Since this is a new file, it will be listed as untracked (i.e., Git hasn't started tracking it yet).
Step 3: Add the File to Git To start tracking the file, you need to add it to Git. Run the
following command:

git add Firstcode.txt

-git add Firstcode.txt: This command stages the file, meaning it prepares it to be included
in the next commit.
-After running this command, the file is added to the staging area, which means it is ready
to be committed to your Git history.

8. Commit the File


After adding the file, you can commit the changes with a message describing what you’ve
done:

git commit -m "first commit message here"

This command commits Firstcode.txt to your Git repository with the commit message "Add
Firstcode.txt".
9.View the Commit History
To see your commit and track the history of changes, use:

git log

This will show a log of all your commits, including the one you just made for Firstcode.txt.

10.How to Move Changes to the Staging Area and Commit:


Step 1: Modify the File
Make changes to your file, for example, FirstProgram.txt. After editing and saving the file, Git
will recognize it as modified.

Step 2: Add the File to the Staging Area


To move the modified file into the staging area (which means Git is now ready to track it),
use the following command:

git add FirstProgram.txt

git add FirstProgram.txt: This command stages the changes made to the file, preparing it
for the next commit. It tells Git to track the new changes.

Step 3: Commit the File


Once the file is in the staging area, you can commit the changes to your Git repository. Use:

git commit -m "my second commit here"

git commit -m "your commit message": This command commits the changes to your
repository with a message describing what you have done. In this case, the commit
message is "my second commit here".

11.Commit Directly Without Staging


Instead of using git add to stage the file, you can use:

git commit -a -m "without staging and commit will be here"

git commit -a: This flag automatically stages all tracked files that have been modified (it
won’t include untracked or new files).
-m "message": The commit message describing the changes.
12. Checking Differences Using git diff:
If you’ve made changes to a file (for example, FirstProgram.txt) and want to see what
changes you’ve made before committing, you can use the git diff command to compare
the current version of the file with the version in the staging area or the last commit.

How to Remove a File in Git:


If you want to remove a file from Git’s version control system but keep it in your local
directory (untracked), you can use the following command:

Step 1: Remove the File from Git Tracking

git rm --cached filename.txt

git rm --cached: This command removes the file from the staging area and the Git tracking
system, but it does not delete the file from your local working directory.
filename.txt: Replace this with the actual name of the file you want to remove (e.g.,
FirstProgram.txt).

Step 2: Commit the Change


Once the file is removed from tracking, you need to commit this change:

git commit -m "Remove filename.txt from Git tracking"

Commit message: This will record that the file has been removed from Git's version
control but remains in your local directory.
CHAPTER 2 (GITHUB VS GIT )
1.Downloading source code in github
Method 1
-If the Github code want your machine go to github and press https and copy the url
And then go for a terminal and enter its start downloading

git clone https://github.com/username/repository-name.git

Method 2
-direct to download zip option

2.creating a file folder using cmd

Creating a Folder and Working with Files Using CMD (Command Prompt)
1. Create a New Folder:
Example: To create a folder named MyProject:
mkdir MyProject

2. Navigate into the Folder:


Example: To navigate into the MyProject folder:
cd MyProject

3. Create a Markdown File (README.md):


echo "# Git Your File Create" > README.md

• Explanation:
o echo "# Git Your File Create": Adds the text # Git Your File Create.
o > README.md: Creates the file README.md with the content provided.

4. List the Files in the Folder:


dir
• Example: Running dir will show the files in the directory, e.g.:
5. View the Content of the README.md File:
type README.md

Example: Running cat README.md will show the content of the file:
# Git Your File Create

3.Creating a Local Git Repository and Committing Files

Step 1: Initialize a New Local Git Repository


To create a new Git repository in your local folder, run the following command:
git init

Step 2: Show All Files (Including Hidden Files)


To display all files in your folder, including hidden files (such as the .git folder), use this
command:
dir -a

Step 3: Add a File to the Staging Area


To add the README.md file to the staging area, run the command:
git add README.md
If you want to add all files in your folder to the staging area, you can use:
git add .

Step 4: Commit the Staged Files to Your Local Repository


To commit the changes you’ve staged, run the following command:
git commit -m "Initial commit: Add README.md"
The -m flag is used to provide a commit message describing the changes made.

4.Connect local repo to remote repo


Step 1: Change the Default Branch Name from master to main
By default, Git creates a branch named master. GitHub and other platforms now
recommend using main as the default branch. To rename the branch:
git branch -m main
This command renames your current branch to main.

Step 2:Generate SSH Key (if you don't have one)


SSH keys are used for securely connecting to your GitHub account without needing to enter
your username and password each time. To generate an SSH key:
ssh-keygen -t rsa -b 4096 -C "[email protected]" -o
• Explanation:
o -t rsa: Specifies the type of key (RSA).
o -b 4096: Sets the key size to 4096 bits for extra security.
o -C "[email protected]": Adds a comment with your email to identify
the key.
o -o: This option saves the key using a new format for added security.

Step 3: Find Your SSH Public Key


Once the SSH key is generated, you need to locate your public key to add it to GitHub. The
default location for SSH keys is the .ssh folder in your home directory. To find it:
1. Go to the directory where the SSH key is stored:
o On Windows: C:\Users\YourUsername\.ssh\
2. Look for a file named id_rsa.pub, which is your public key. You can open this file to
view its content.

Step 4: Link Your Local Repository to the Remote GitHub Repository


Once your SSH key is added to GitHub, you can now connect your local repository to a
remote repository on GitHub.
Add the remote URL (replace your_username and your_repository with your GitHub
username and the repository name):
git remote add origin [email protected]:your_username/your_repository.git

Step 5:push local copy to remote copy


git push -u origin main once enter it will be push into the git gub

Over all Process adding new file


THIS STEP WILL BE SUCCESS FULLY DONE PUSHING THE GITHUB

CHAPTER 3 ( WORKING WITH TAGS)

Some important tags


1.Git remote -v
It will be shows the origin links for server to client and vice versa link

2.tagging
There two type of tagging

Setup new tag

Once the new version released in compare to the previous release use to list the
tags
3.how to push tag

This commad will be ush the tag into the github

4.finnaly git hub will be show for a tag like this

CHAPTER 4(CLONE PROJECT)

This example how to clone a vs code

Chapter 5 branching
1.Create a new branch method1

Feature1 is a branch name


b-create new branch keyword
1.1Create a new branch method 2
2.how to see which branch is active

*indicates is active branch

3.how to change a branch

Will any modification will be done in features1 branch once it will be switch to the main
branch its automatically disappears what are the changes will be made in this feature
branch

4.how to delete a branch

This command will be execute to delate branch

5.how push a branch into the github remote repo

Which branch you want to push into the remote git in tnis case we add features 1 branch wil
be pushed

5.merge two branch

Am in main branch and merge the features branch into the main branch(don’t push in real
project directely)

6.how to pull

Once it will be pull merge changes will be seen in this github profile

You might also like