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

githubNotes-1

This document provides a comprehensive guide on using Git and GitHub, covering user setup, the three-stage architecture of Git, and commands for managing repositories. It explains file status life cycles, how to ignore files, and accessing remote repositories, as well as branching strategies for collaborative development. Key commands and their descriptions are included to assist users in effectively utilizing Git for version control.

Uploaded by

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

githubNotes-1

This document provides a comprehensive guide on using Git and GitHub, covering user setup, the three-stage architecture of Git, and commands for managing repositories. It explains file status life cycles, how to ignore files, and accessing remote repositories, as well as branching strategies for collaborative development. Key commands and their descriptions are included to assist users in effectively utilizing Git for version control.

Uploaded by

meprojects.gg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Git & GitHub Notes

• User Setup of Git


While committing changes for any project, git should know who is doing all
these changes. So, for that we have to maintain User in git.
Set user name and email using following command
git config –global user.name = <username>
git config -global user.email = <email>
i.e.:
git config –global user.name = john
git config -global user.email = john28@gmail.com

for getting metadata about user write following command


git config --list

• Git- Three stage architecture


Local Operations

Working directory Staging Area git repository

Checkout the project

Stage files

Commit
➔ Working directory is a workplace where we are simply making our
project files.
➔ Staging area contains files that we want to commit
For Example: If you create a project which contains following files
Index.html, script.js, style.css
If you want to improve your project by changing in each file (modify
source code) and create version 2 of your project. But here you find bug
in script.js and you want to keep changes made in index.html and
style.css you can put both files in staging area and continue to modify or
resolve script.js
➔ Those files you want to take in next commit you can put it in staging
area.

• Tracing the directory using ‘git’


When you initialize any repository/directory as git repository/directory, all the
files which is inside that directory or files which would be created in future
inside that directory would be under the track of the git.
Commands Description
git status To check, whether your repository is git
repository or not, and if your repository is
git then it will show the status of all the
tracking files, whether files are deleted,
modified, staged or committed, etc.
git init To Initialize any repository as git repository.
git add file1.txt To add newly created or modified files into
git add file2.html file1.txt staging area.
git add -–all Last 3 commands add all the files from
git add -–a staging area
git add .
git restore <filename> Restore file from the staging area or un-
git restore index.html stage any files.
git restore –-all Last 3 commands restore all the files from
git restore –-a staging area
git restore .
git commit -m “Initial commit” To commit the changes and give a short
message for that commit. Committing
changes means git would create a snapshot
of your repository.
git log Display the log of all the commits made on
your directory.
git log -p Display every log with the details, how
many lines are added, deleted or modified.

Now once your directory become git directory you can also make it normal
directory by writing following command
rm -rf .git
when you initialize your directory as git repository it will create one hidden
folder named .git which contains all the information of the directory and all the
snapshots of the directory.
By writing above command, you are removing that file forcefully.
Note: But be careful while writing this command. It will clear all he commits
and trace of your directory and won’t trace anything, you may lose your
important commits also.

• Git file status life cycle

Untracked Unmodified Modified Staged

Add the file

Edit the file

Stage the file

remove the file

Commit

➔ First time when you check directory status exactly after creating git
repository, all the files are ‘untracked’.
➔ When you add files for first time it will become ‘unmodified’. Which
indicates that tracking of files now started. If you modify any file you will
show the ‘modify’ status.
➔ All the file you put in the staging area would be marked as ‘A’ means
added in staging area.
➔ And after the commit snapshot of your repository would be taken and all
the marks would be removed. Which means it is marked as ‘unmodified’
by git. Again, you make any change after commit it would marked as
‘modified’
➔ In visual studio code you will see the character sign following the file
name which indicates as follows:
U: Unmerged/ Untracked
A: Addition of the file
D: Deletion of the file
M: Modified the file
R: Renamed the file
T: Changed the type of the file

• Ignoring the files


In some cases, you want that some of the files and directory should not
be tracked by git. You can ignore that files by putting name of the file,
name of the directory or files which extensions are similar into
‘.gitignore’ file
Ex: Your folder contains /node_module, or .exe files you can ignore them
by placing folder name and .exe into .gitignore file

Git would not trace /node_module folder and all the files which
extension is .exe

- In other case, if git is currently tracking your file and certainly you
want that this file should not be tracked by git, Then you cannot
directly write the name of the file in .gitignore file , you have to first
make it untracked by writing following command .
- You can directly ignore that files only which are untraced by git. So,
for ignoring files which are already tracked by git you first have to
untracked it.
git rm --cached <filename>
git rm --cached hello.exe

• Accessing remote repository and pushing it to GitHub


Commands Description
git clone url Clone the remote git repository to your
local machine
git remote Display the list of the remotes (remote is a
git remote -v url which refers to your remote repository)
git remote add <alias> <url> Add the remote as given alias to your local
git remote add origin git repository
https://address to your remote
repository
git remote remove <remote Remove remote from your local git
alias> repository
git remote origin

git push -u origin <branch Push your local repository to remote


name> repository (GitHub).
git push -u origin master

git pull Pull all the changes made in remote


git pull <branch name> repository to your local repository

• Branches in git
When you are developing any application by collaborating on same project
you may not want to risk original production reside on main/master branch.
Any developer can create the branch and work only on that branch, after that
if manager or leader of the project found that changes made on different
branch is considerable then he/she can merge the branch to the main/master
branch or can discard the changes by deleting the branch.
Commands Description
git checkout -b <branch_name> Create the new branch of given name.
git checkout -b myBrc i.e: Create a new branch by the name of
myBrc
git checkout <branch_name> Switch to the desire branch.
git checkout master i.e: Switch to the master branch
git branch Display list of the branch, and marked
current branch as asterisk
git branch -d <branch_name> Delete the branch which is already pushed
or merged
git branch -D <branch_name> Forcefully delete the branch even if its not
merged yet.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy