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

Git - Notes

Git is a version control system that allows tracking changes to files. It uses branches to isolate work, and commits to capture snapshots of changes over time. Common Git commands include git add to stage files, git commit to commit changes, and git push to sync local changes to a remote repository. Git resolves conflicts when merging branches by comparing differences between commits.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
325 views

Git - Notes

Git is a version control system that allows tracking changes to files. It uses branches to isolate work, and commits to capture snapshots of changes over time. Common Git commands include git add to stage files, git commit to commit changes, and git push to sync local changes to a remote repository. Git resolves conflicts when merging branches by comparing differences between commits.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Git

 Different types of settings

 Type “Code” to open Visual studio Code editor as below


 To set as default editor , wait flag is used to represent to wait to open new editor

 To make notepad++ as default editor , To get all configured variables.

 To modify the global settings in editor , until visual studio code editor closed this didn’t allow to type other
command .

 To get list of commands associated with git config


Git config –list

 To configure git in Mac Osx – TextMate


 To set up identity to global data

To get help of any command – git help <verb>


git <verb> --help
It display commands in browser.

 How to add alias name for notepad++ in git using bash_profile


C:\Users\BALAJI\.gitconfig

 Usage of enter in different operating systems

Core.autocrlf : This is used by avoid issues while checkin from windows and MacOS

For Windows: Core.autocrlf true

For MacOsx: core.autocrlf input

For windows

To get help for git commands. Type in command prompt


Pwd – This is used to show where our location i.e folder

 Creating a folder and initializing git

 .git is hidden folder , to list files inside the folder ls –a

 Staging area/ index is existed in git , it is used to pre check before doing commit to our repository.

 To add file to a folder “Moon” – files to add file1.txt ,file2.txt

 To add files to staging area

 To get status of files


 To edit a file use echo <directoryName> >> <filename>

If file is in edit mode, staging area will contain the old file ,to update it we need to run git add

Before commit our changes we need to modify it in configured editor.

Git commit command is used.


 To commit a file without adding to staging area

 To list files in staging area

 If we deleted a file using “rm” ,we need to update them in staging area before doing removal.
 Commit using message –m

 To remove file from working directory and staging area

 To rename file1.txt as main.js

 To rename or move file ,it effect both working directory and staging

 If we commit the change after we rename a file

 To avoid folder or files that shouldn’t track by git , create a file .gitignore

 Add all ignore files and folders in .gitignore file


 To remove a folder / file from staging area

 To get status in short information

 If existed file had modification , then M will display before a file ,?? Is new files that not added to staging area

 If file2.js is added , it show A as “Added”


To view the staging area changes ,that will commit in next release.

 Configuring tool as vscode to get difference of files


 Above command is used to open file1.js in vscode by showing differences

 To compare a file within staged file

To see the history there is Log command

Commit identifier – 40 character Hex Decimal – unique identifier

Master is the main branch , HEAD is reference to current branch .

 To show log in one line


 Reverse: To print log in reverse order

 To view the first commit from history

 To check a file what checked in

 To get list of files in a check in

 List of git objects


 The "restore" command helps to unstage or even discard uncommitted local changes.

 To undo all file changes

 To remove local files use clean command


Commit: Captures a snapshot of the project's currently staged changes

For first time , every developer clone to git (Copy code from repository).

 Git will track all files, if files are tracked then it is Tracking and files are not tracked then it is Untracking .

 Staging Area is also called as Index .


 For initial code taken from GitHub is called Master (branch) – Mainline .
 We create Feature branch as we required. i.e Feature1 ,Feature2,Feature3

Origin: This is name of location where we get code.


 To get project /clone we need a repository url

 We use two types of protocols to cone repo i.e SSH , HTTPS

1. Type in the following: ssh-keygen -t rsa (when prompted, enter password, key name can


stay the same)
2. Open file your_home_directory/.ssh/id_rsa.pub with your favorite text editor, and copy
contents to your Git repository’s keys field (GitHub, beanstalk, or any other repository
provider), under your account.
3. Be sure that you don’t copy any whitespace while copying public key’s content
(id_rsa.pub)

Run ssh -o StrictHostKeyChecking=no git@github.com in command prompt to add the authenticity to your


known_hosts. Then you won't get the prompt the next time.
Add a local folder to Repository

-u represents – Upstream .
Note: If we want to include one javascript file among all files ,we should use negation operator .
For e,g: if you want to show main.js
!main.js should include .gitignore

Status : It show the state of file


Diff: It display the difference of file contents

Git commit : This is used to commit the file


To commit with changes use Git commit –v
Here –v is verbose.
Git log –p
Git log -2
Git log –pretty=oneline
Git log –pretty=short
Author: Who initially commited the project into repository
Commit: Who will add new changes to repository
This is default branch when we create initially.

Root-commit: This is created at first time we commit.

Commit had 40 character id, it internally generated.

Second Snapshot B is derived from Snapshot A .


Snapshot B parent contain Snapshot A ID.
Master is pointer to commit. Master always pointer to most recent commit as show below.

Created a branch named as “side-menu”

Git log shows two branches – master , side-menu


HEAD always points to current mapped branch.
 To shift from one branch to another use checkout option.

 After commit done for new file nav_bar.html , HEAD will point to side-menu branch commit as below
Git log always give current branch commit list. If we want to get all branch list we have to use
Git log –oneline –all

 To view log in graph mode


Git log –oneline –all –graph
 To create a new branch and we switch to that branch simultaneously.

 This is concept of merging child branch to master


Check out to master
Printed the address.html
Merged the branch to master
Printed the address.html (After merge)
Here, a file that modified in one branch (email-fix) is merged to other branch (master)

To delete a unused branch use command git branch –d branch name

 To list which branch are merged or non-merged

 To list all branch


 If same file is modified in two different branch , if we want to merge into master then conflict issue will come

To get all commits in a graph


Git log –oneline –all –graph

Remote branching
 To know name of remote server

 Log after we downloaded from remote branch

 After make modification and made commit ,then log again

 To fetch a new file from remote repo

 New file will stay under remotes/origin/master , we need to pull that file
 To pull from origin/main

 Fetch command fetch file and store in remote then we need to merge file.
In pull command we need can fetch and pull the file into our master /main branch

If e modify a local file ,before pushing the file we need to pull


To disable prompt for diff , merge tool
 To add alias to any command use git config –global alias.<name of user defined> “path without git”

Rebasing is the process of moving or combining a sequence of commits to a new base commit.
Rebasing is most useful and easily visualized in the context of a feature branching workflow. ... This
gives the later benefit of a clean merge of your feature branch back into the master branch.
Git rebase branch
Git mergetool – this open p4 merge tool we consider one of the change to commit
Git rebase continue
Git commit –m “comment”

Git stash always consider staged files only. It can’t add /track untracked files.
Git stash –u // This is used to add untracked files into stash.

Git clean apply on untracked files only.


Git clean –f

To clean both files and directories


Git clean –f –d
We always move .gitignore to stag area /index area , then we can try with –x command

 Above command make dry run and list all files which will remove ,if I run clean command .

 This is used to log the version id ,after which commit we did.


To get all tags git tag –l

 To add tag , git tag <name of tag>

 To get difference between two tags


Git diff v1.0 v2.0
 To delete a tag

 To give tag to a commit number

 To shift tag from one commit number to other

To push all tags to repo


Git push origin –tags

You might also like