Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Git and Github

Uploaded by

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

Git and Github

Uploaded by

Subrata Ray
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Git and GitHub

Git is a version control software. In one way or the other you may need to use a git and a
GitHub together.

Git = Control Version System.

1. Install Git
First, you need to install the version control software, Git.

 Git: Install git .

2. Checking status of the repository


The git status command allows you to know the status of the project: If it is

 initiated
 modified
 staged

We can write the command git status at any time. It is a means to to check what is
happening on your project.

3. Configure your name and your email


Open the Git bash if your device is Windows.

git config --global user. email subrata.623@gmail.com


git config --global user.name "subrata623"
git config –list

4. Create a Working Directory


mkdir project_name
cd project_name
5. Initialize Git
git init

Initialized empty Git repository in D:/gitprojects/project1/.git/. git is an empty repository,


which is hidden directory.
6. Add file to the staging area
To add files from working directory to staging area for tracking/committing purpose, we
must use git add command.

i) To add all files present in current working directory.


git add.
ii) To add one or more specified files git.
git add a.txt git add a.txt b.txt
iii) Even we can use pattern.
git add *.txt git add *.java.

7. Git status:
It shows the status of all files in each area, like which files are untracked, which are
modified, which are staged etc.

8. Git status
on branch master Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: a.txt
modified: b.txt.
no changes added to commit (use "git add" and/or "git commit -a")
git status -s
9. Git commit:
git commit -am 'commit message’.
git commit -m "Your Message here" (commit your changes, attach a message, create
save point)
git commit -a -m "commit message”.
-a means adding files to staging area
-m means commit message, but this command will work only for tracked files but not
for new files.
git commit -am "commit message"-> Valid.
10. Git log:
It shows history of all commits. It provides commit id, author name, maild , timestamp
and commit message.
git log
git log –help
11. Git Checkout
We can use checkout command to discard unstanged changes in the tracked files of
working directory. Observe the 3 words:
1) Only for working directory
2) To discard unstaged changes(The changes which are not added to staging area)
3) In the tracked files (The files which are already added to staging area/commit)

git checkout – filename


To discard changes in working directory copy. it copies staging area (usually last commit)
to out working copy
git –version

C:\Users\eraysub\subrata\subrata1>git init

Initialized empty Git repository in C:/Users/eraysub/subrata/subrata1/.git/

cd C:\Users\eraysub\subrata\subrata1\rhcsa9

git add –all

git commit -m "add all file "

git commit -m "add all file "

git log

git remote set-url origin https://github.com/subrata623/repo1.git

C:\Users\eraysub\subrata\subrata1\rhcsa9>git remote -v

origin https://github.com/subrata623/repo1.git (fetch)

origin https://github.com/subrata623/repo1.git (push)

git config --global user.email subrata.623@gmail.com

git config --global user.name "subrata623"


git config --list

git push -u origin main

git remote add origin 'https://github.com/subrata623/repo1.git'

git clone https://github.com/subrata623/repo1.git


Git in ubuntu:
sudo apt-get install git

Set up:
 git config --global user.name "User Name"
 git config --global user.email email@email.com

Create a New Project:


 mkdir project
 cd project
 git init (initialise empty git repo in my folder (based on path) aka .git
folder)
 ls -la (check my folder)

Check "world status":


git status
Help for each command
git help <command>
Add files.

 git add . = add all on current branch.


 git add -p <param=file> = add part of file to staging area, ask for
each change (if no param => all files) so we have more control and
cleaner commits. After any git add, we need a git commit, either a
file or a pattern (e.g. *.txt)

Delete a file
 git rm <filename> = deletes a file, updates git and then commit!
 git rm --cached <filename>" = delete a previously tracked file

Check difference

 git diff= displays what will be added if i git add, so what changed
in the folder and hasn't been updated yet
 git diff <filename> = displays the alterations of a file (the modified
and the commited versions of it)
 git diff --staged = displays what has already been added and thus
what changed will be recorded
 git diff HEAD = displays changes since last commit
Display history
git-log = displays the history, the chronologival order of commits (based
on their IDs), who did them, what was their description
git show <id> = displays what the commit did = git log + git diff
Cancel not staged changes.
git checkout = it copies staging area (usually last commit) to out working
copy.
Reset
git reset- remove all that exists in my staging area by copying them from
the most recent commit (basically undoes git add)

What does git commit do?


 commit a file = create a snapshot of the current world state (files, folders
& their contents)
 contains an explanatory message
 automatically stores metadata (creator, date etc)
 has a unique (hex) id number
e.g.: git commit -m "Added README file

Combinations

 git commit -a = git add + git commit (not desirable due to lack of
control)
 git pull = git fetch + git merge (very useful)

Collaborate
Show remote: git remote

Show remote details: git remote -v

Add remote upstream from GitHub project: git remote add upstream
https://github.com/user/project.git

You might also like