Git Fundamentals for beginner:
Learn important git commands
Learn Remote repo and Local Repo
GitLab
In this webinar, we will learn Git Fundamentals.
To watch the webinar visit: https://www.youtube.com/channel/UCU4mwvQ8ZAl1Uk7SkeVNuOg?view_as=subscriber
8. Creating a local repository
Command to use:
8
git init
Example:
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1
$ git init
Creates a new git repository in a particular folder.
OR
Creates a new local repository with the specified name
16. Git Status Command
Command to use:
16
git status
git status -s
git status -v
Example 1:
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1 (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: src1/demo.txt
new file: src2/demo.txt
new file: src3/demo.txt
Shows the state of your staged and unstaged files.
17. Example 2
17
Command: git status -s
Outputs the file in shortend format
Example:
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1 (master)
$ git status -s
A src1/demo.txt
A src2/demo.txt
A src3/demo.txt
?? readme.txt
A: Files are staged
??: Files are not tracked
18. Example 3
18
Example: Stage the new file using git add readme.txt
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1 (master)
$ git status -s
A src1/demo.txt
A src2/demo.txt
A src3/demo.txt
A readme.txt
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1
(master)
$ echo "jatin" >>readme.txt
jatin@LAPTOP-LEI7GM17 MINGW64 ~/Desktop/AT-Batch May1
(master)
$ git status -s
AM readme.txt
A src1/demo.txt
A src2/demo.txt
A src3/demo.txt
19. Example 4
19
Command: git status -v
Outputs the file in verbose format (Means detailed output)
Example:
In Comment Section
21. Commiting to Git Repo
Command to use:
21
Git commit
Git commit -m “Commit Message”
Git commit -a -m “Message”
Long Way:
Opens a text editor so that you right your commit message!
Shorter Way:
Git commit -m “Commit Message”
Git commit -a -m “Message”
23. Ignoring file in git
Command to use:
23
Create a file call .gitIgnore
.gitIgnore will ignore files in a git repository.
Files are excluded based on wildcard pattern!
27. Tag in Git
Command to use:
27
git tag -a [tag] -m "msg"
A TAG is used to mark a specific commit in your project.
Eg Version Number.
Two Types of Tag in Git:
1. Annotated Tags
2. Lightweight Tags
28. Annotated Vs LightWeight
Lightweight tags are just pointers to specific commits. No further information is
saved.
Annotated tags are regular objects, which have an author and a date and can be
referred.
If knowing who tagged what and when is relevant for you, then use annotated
tags.
If you just want to tag a specific point in your development, no matter who and
when did that, then lightweight tags are good enough.
Mostly All companies used Annotated Tags
28
30. Branches
Command to use:
30
Git branch <branch Name>
Git Checkout <Branch Name>
This is helpful so that you can work on a different development line
without altering your stable line of work.
31. Merging Branches
Command to use:
31
Git branch <branch Name>
Git Checkout <Branch Name>
This is helpful so that you can work on a different development line
without altering your stable line of work.
34. Rebasing
Command to use:
34
Git rebase <branch Name>
Git Checkout <Branch Name>
Rebasing and merging are both designed to integrate changes
from one branch into another branch but in different ways.
You would likely use a rebase method of applying changes when you want
to push your own work to a remote repository
37. Log Command
Command to use:
37
Git log
Git log --graph
Git log --stat
use the built-in logging functionality of git to keep track of what's going
on with the repository. We will use the git log command and some of its
more common options to format the log's output.
39. Clone Command
Command to use:
39
Git clone <localrepo> <new repo>
clone a local repository as a backup or as a testing ground for features or database
work
40. Clone usin HTTPS
Command to use:
40
Git clone <url>
clone remote repositories from popular sites such as GitHub onto your local system. We will clone over
HTTPS, and show you what you get when you clone a project
42. Tracking a repo
Command to use:
42
Git remote -v
Shows the remote server that are being tracked for the current repository.
43. Fetch from Repo
Command to use:
43
Git fetch origin
Fetches new commit information from the remote server (eg github,gitlab) for the current repository.
It will not merge the files automatically on your local system.
If you want to pull automatically you need to use the git pull command.
44. Pushing to Remote Repositories
Command to use:
44
Git push -u <remote> <local>
Fetches new commit information from the remote server (eg github,gitlab) for the current repository.
It will not merge the files automatically on your local system.
If you want to pull automatically you need to use the git pull command.