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

Git

Notes on Git and GitHub

Uploaded by

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

Git

Notes on Git and GitHub

Uploaded by

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

Introduction to git

BY: Manoj
GIT
 Commonly used version control system(going back to older version if new version
as bug)

 Tracks the changes you make to files, so you have a record of what has been done.

 Makes collaboration easier, allowing changes by multiple people to all be merged


into one source.
Git is software that runs locally.

Your files and their history are stored on your computer.

You can also use online hosts (such as GitHub or Bitbucket) to store a copy of the files and their

revision history.

Having a centrally located place where you can upload your changes and download changes

from others, enable you to collaborate more easily with other developers.

Git can automatically merge the changes, so two people can even work on different parts of the

same file and later merge those changes without losing each other’s work!
Git is used for

 Tracking code changes

 Tracking who made changes

 Coding collaboration
What does git do?
 Manage projects with Repositories

 Clone a project to work on a local copy

 Control and track changes

 Branch and Merge to allow for work on different parts and versions of a project

 Pull the latest version of the project to a local copy

 Push local updates to the main project


Why git?
Control Changes: Git helps developers keep track of changes made to their code, making it
easier to see what was added, removed, or modified.

Work Together: It lets multiple people work on the same project at the same time without
messing up each other's work.

Backup Your Code: Git stores your code history, so you can always go back to a previous
version if something goes wrong.
Safe and Secure: It's designed to keep your code safe from unauthorized access or accidental
changes.

Free and Open: Git is free to use and open to everyone, with a big community of users and
helpers.

Compatibility: You can use Git on different computer systems like Windows, macOS, and
Linux.

Saves Time: Git's features like branching and merging help teams work more efficiently and
avoid conflicts in their code.
GITHUB
 GitHub is an online software development platform. It's used for storing,
tracking, and collaborating on software projects.

 Is like a website where people, especially computer programmers, can work


together on creating and improving computer programs.

 Is a hosting service for git repository, is cloud based

 GitHub is the service for projects that use Git


Here's what you can do with github:
1. Store Code: You can put your computer code on GitHub, so you don't lose it, and

others can see it if you want.

2. Work Together: If many people want to help with a project, they can all work on

it at the same time without messing things up.

3. Fix Mistakes: If someone makes a mistake in the code, others can check it,

suggest changes, and then the mistake can be fixed.


4. Track Problems: You can keep a list of problems or things to do, so you don't forget them. This
helps everyone know what needs to be done.

5. Test Automatically: It can automatically test if the code is working correctly, which saves time
and avoids errors.

6. Share Your Work: If you create a website or something similar, you can show it to the world on
GitHub for free.

In short, GitHub is a helpful tool for programmers to work on code together, keep track of changes, and
make sure everything works smoothly.
Git repositories
Contains all of the project files and the entire revision history
Branches & Merging
1. Let’s say you need to work on a new feature for a website.

2. You create a new branch and start working.

3. You haven’t finished your new feature, but you get a request to make a rush change that needs
to go live on the site today.

4. You switch back to the master branch, make the change, and push it live.

5. Then you can switch back to your new feature branch and finish your work.

6. When you’re done, you merge the new feature branch into the master branch and both the new
feature and rush change are kept!
Git commands when working with local repositories

git init:

1. converts a directory into an empty repository.

2. Is the initial step you need to take to build a repository


git add:

1. Allows you to add files in the Git staging area.

2. We can use this command to add directories, files, etc.

git commit:

1. Allows you to track the changes in the files in a local repository.

2. Each commit has its own unique ID for reference.


git status: The git status command returns the present state of a repository, like if the file is in
the staging area but has not been committed.

git branch:Determines the branch of the local repository and allows you to add or delete a
branch.

git checkout: We can use this command to switch to another branch.

git merge: The merge command allows us to integrate two or more branches together. It
combines the changes made in the branches.
Git commands when working with remote
repositories

git remote: This Git command allows you to connect a remote repository to a
local repository.

git pull: copies the changes made to a project to the local repository from the
remote one.

git push: Copies the changes made to a project to the remote repository from
the local one..
git clone:

We can use the clone command to create a local copy of an already existing remote
repository.

This allows us to copy and download the required repository to the system.

It allows you to build a local directory, consisting of all the necessary files and
history of the repository.
Recording changes to the repository
git clone https://github.com/manojmanumr13/Assignment-UI.git

Git status=>gives untraked file


Git add . => the file will be added to git
git commit -m "saveData“=> saves into git
Git push orgin main=> push to main branch
Git pull:

If i added any file in git web, if I need to pull into my local we can use git pull
If I want to change the branch from master to main
Git branch –M main

To know which branch we are working


Git branch
If I want to change the branch:
git init –b main

Try to use main instead of master branch


If I don’t want to type git add . And git commit

We can use
Git commit –a –m “fghjhbj”

If I want to know changes made: git diff


If I want to remove file: git rm –cached cred.txt
First delete in local repo then run the command
BRANCH CREATION
Git checkout –b newbranch
to check branches-> git branch

Or to switch between branch:

Git switch main


Git switch newbranch
Git branch –all==>gets all branch

If u want to go back to branch=> git branch –

To push the new branch =>git push origin new


To merge=> git merge
Before use command git pull origin main

Delete branch
git push origin --delete branchname

You might also like