Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views8 pages

Git Instructions

The document provides a comprehensive overview of essential Git commands and their usage, including initializing a repository, checking status, adding files to staging, and committing changes. It also covers advanced commands related to branching, tagging, and remote repository management on GitHub. Key commands are listed with examples to facilitate understanding and practical application.

Uploaded by

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

Git Instructions

The document provides a comprehensive overview of essential Git commands and their usage, including initializing a repository, checking status, adding files to staging, and committing changes. It also covers advanced commands related to branching, tagging, and remote repository management on GitHub. Key commands are listed with examples to facilitate understanding and practical application.

Uploaded by

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

GIT Notes:

Commands:
git --version : gives current version of git
git init : creates git repository in current folder
in folder it then creates two parts one where we work and store our files and second which is hidden
from user is staging area which tracks the progress of the files.

git status : The git status command is used in Git to display the state of the working directory
and the staging area. It shows which changes have been staged, which have not, and which files are
not being tracked by Git. This command is essential for understanding the current status of your
project and making informed decisions about your next steps. When you run git status, Git
categorizes files into several sections: changes to be committed (staged), changes not staged for
commit (unstaged), and untracked files. The command helps you keep track of modifications, added
files, and deleted files, ensuring you are aware of all changes before committing
them. Additionally, git status provides suggestions on how to proceed, such as using git add to track
untracked files.

Eg:
__________________________________________________________________________________________

PS X:\code\Git> git --version

git version 2.50.1.windows.1

PS X:\code\Git> git status

fatal: not a git repository (or any of the parent directories): .git

PS X:\code\Git> git init

Initialized empty Git repository in X:/code/Git/.git/

PS X:\code\Git> git status

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

PS X:\code\Git>

__________________________________________________________________________________________
By Default while installing we set the Git as ‘On branch master’ as you can see in above example
But mostly we should us ‘On branch main’ for that:

PS X:\code\Git> git status

fatal: not a git repository (or any of the parent directories): .git

PS X:\code\Git> git init -b main

Initialized empty Git repository in X:/code/Git/.git/

PS X:\code\Git> git status

On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

PS X:\code\Git>

If any File not added in git staging area its showed as untracked file in git status:

PS X:\code\Git> git status

On branch main

No commits yet

Untracked files:

(use "git add <file>..." to include in what will be committed)

FirstCode.txt

nothing added to commit but untracked files present (use "git add" to track)

PS X:\code\Git>
To add file into staging area we use -> git add FileName.extension.

PS X:\code\Git> git add FirstCode.txt

PS X:\code\Git> git status

On branch main

No commits yet

Changes to be committed:

(use "git rm --cached <file>..." to unstage)

new file: FirstCode.txt

__________________________________________________________________________________________

PS X:\code\Git> git log

fatal: your current branch 'main' does not have any commits yet

PS X:\code\Git> git commit

Aborting commit due to empty commit message.

PS X:\code\Git> git commit -m "First Commit"

[main (root-commit) 8b12fd5] First Commit

1 file changed, 1 insertion(+)

create mode 100644 FirstCode.txt

PS X:\code\Git> git status

On branch main

Changes not staged for commit:

(use "git add <file>..." to update what will be committed)

(use "git restore <file>..." to discard changes in working directory)

modified: FirstCode.txt

no changes added to commit (use "git add" and/or "git commit -a")

PS X:\code\Git> git log

commit 8b12fd5b1d93a92b2938dc1527f9018ccc51d0b2 (HEAD -> main)


Author: avanish <[email protected]>

Date: Thu Jul 24 15:29:08 2025 +0530

First Commit

PS X:\code\Git>

__________________________________________________________________________________________

git log : Git log is a command in Git that displays the commit history of a repository, including
details such as author, date, and commit message
__________________________________________________________________________________________

Everytime you want to commit u have to first add that file to staging area by (git add …) and then use
(git commit -m “msg”)
__________________________________________________________________________________________

PS X:\code\Git> git commit -m "added description"

On branch main

Changes not staged for commit:

(use "git add <file>..." to update what will be committed)

(use "git restore <file>..." to discard changes in working directory)

modified: FirstCode.txt

no changes added to commit (use "git add" and/or "git commit -a")

PS X:\code\Git> git add FirstCode.txt

PS X:\code\Git> git commit -m "added description"

[main dff30e2] added description

1 file changed, 2 insertions(+), 1 deletion(-)

PS X:\code\Git> git status

On branch main

nothing to commit, working tree clean

PS X:\code\Git> git log

commit dff30e264018957aab0d3936b31222789d8884e8 (HEAD -> main)

Author: avanish <[email protected]>

Date: Thu Jul 24 15:37:35 2025 +0530


added description

commit 8b12fd5b1d93a92b2938dc1527f9018ccc51d0b2

Author: avanish <[email protected]>

Date: Thu Jul 24 15:29:08 2025 +0530

First Commit

PS X:\code\Git>

commit 8b12fd5b1d93a92b2938dc1527f9018ccc51d0b2

Here in above line the ‘8b12fd5b1d93a92b2938dc1527f9018ccc51d0b2’ is a checksum value

Basically git generates this values by SHA-1 algorithm to identify each unique commit .. it consists of
40 characters.

Now if you don’t want to do git add everytime u can do this:

git commit -a -m "msg"

PS X:\code\Git> git commit -a -m "My Third Commit"

[main e432694] My Third Commit

1 file changed, 7 insertions(+), 1 deletion(-)

PS X:\code\Git> git log

commit e4326940f3e1fb356afb8df567c28a9adc4d94a6 (HEAD -> main)

Author: avanish <[email protected]>

Date: Thu Jul 24 15:46:10 2025 +0530

My Third Commit

commit e4326940f3e1fb356afb8df567c28a9adc4d94a6 (HEAD -> main)

Author: avanish <[email protected]>

Date: Thu Jul 24 15:46:10 2025 +0530

My Third Commit
commit e4326940f3e1fb356afb8df567c28a9adc4d94a6 (HEAD -> main)

Author: avanish <[email protected]>

Date: Thu Jul 24 15:46:10 2025 +0530

My Third Commit

commit dff30e264018957aab0d3936b31222789d8884e8

Author: avanish <[email protected]>

Date: Thu Jul 24 15:37:35 2025 +0530

added description

__________________________________________________________________________________________
GIT COMMANDS:

1. git --version
2. git init
3. git status
4. git log
5. git add
6. git init -b main
7. git add FileName.Extension
8. git commit -m “message”
9. git commit -a -m “message”
10. git diff
11. git diff –staged
12. git add . – (adds all files from folder to git directory)
13. git rm --cached Creds.txt – (remove staged directory and manually remove
normal directory)

GitHUB:
14. git clone https://githubHTTPLink --(creates github directory locally)
15. echo “#git-course-demo” >> README.md – (Creates readme.md file in directory with
content - #git-course-demo.

16. git branch -M main –(makes current branch main)


17. ssh-keygen -o - (creates public/ private rsa keypair to login securely find the key in local home
folder then in .ssh folder where you will find id_rsa.pub file. Open that file you will get the key. Copy that entire
key and in github go to “settings” then go to “SSH and GPG Keys” then “new SSH key” and paste and create
new key. Now client gets secure access to git)

18. git remote add origin [email protected]:<username>/<repository>.git (add a


remote repository to your local Git project)
19. git push origin BranchName push the local connected repo to github repo
20. git remote -v lists the remote repositories connected to your local Git project

21. git tag -a v1.0 -m "message" : creates an annotated tag named v1.0 with a
message, marking a specific commit (often for versioning/releases).
22. git tag : to check tags in project
23. git checkout -b BranchName : creates a branch and switches to it.
24. git checkout BranchName : switch to given branch name
25. git branch : returns total branches in project
26. git swtich BranchName : switch to given branch name
27. git swtich -c BranchName : create and switch to new branch
28. git switch - : switch to previous branch
29. git branch -d BranchName : deletes the branch
30. git merge BranchName : merge current branch with specified branch
31. git rebase BranchName :
32. git stash : temporarily saves uncommitted changes in a hidden stack so you
can work on something else and come back to them later.
33. git stash apply: applies the most recently stashed changes to your working
directory without removing them from the stash list.

You might also like