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

Git Commands

Uploaded by

DILEEPKUMARRR
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Git Commands

Uploaded by

DILEEPKUMARRR
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Git Commands

• VCS- Version control System-Maintains different versions of code.


• There are two types of version control systems .
• 1. Centralized VCS
• 2. Distributed VCS

• Git is a Distributed version control system.

• Git Workflow:

• It has working directory, local repository and remote repository.


Centralized Version Control System
Distributed Version Control System
Difference Between CVS and DVS

Centralized Version Control Distributed Version Control

In CVS, a client need to get local copy of source from server, do the In DVS, each client can have a local branch as well and have a complete
changes and commit those changes to centeral source on server. history on it. Client need to push the changes to branch which will then
be pushed to server repository.

CVS systems are easy to learn and set up. DVS systems are difficult for beginners. Multiple commands needs to
be remembered.

Working on branches in difficult in CVS. Developer often faces merge Working on branches in easier in DVS. Developer faces lesser conflicts.
conflicts.

CVS system do not provide offline access. DVD systems are workable offline as a client copies the entire
repository on their local machine.

MKS Tech Talks


CVS is slower as every command need to communicate with server. DVS is faster as mostly user deals with local copy without hitting server
everytime.

If CVS Server is down, developers cannot work. If DVS server is down, developer can work using their local copies
Git Work-Flow
How to connect AWS ec2 from Windows
• Go to Putty.org
• Download putty.exe
• Download puttygen.exe
• Using puttygen we can convert .pem into .ppk
• Using load option take corresponding .pem key
• Select Save private key
• Now puttygen will generate .ppk key
• Save .ppk key
• By using this .ppk key we can log on into AWS ec2 instance
• When we install git, we have to configure below

• Git config- -global user.name “gayazsheik”


• Git config- -global user.email “gayazsheik7@gmail.com”
• git config - -list  checking for settings
• git config - - global - -list
• git config - - global - -edit
Git Commands
• Git Init
• Git Status

• Git add filename

• git add .

• git commit -m “Message"

• ls --- it will show working dir files

• git ls-files --- it will show files in local repo

• history
Git Commands

• git log

• git log –oneline

• git show ‘commit id’ --- it will show what changes made in that

particular commit

• git commit -a -m "message" : we can use this to perform both

add and commit with single command . it is used only if we

change all ready committed files


Git Commands

• git diff-- it will show the file modifications which are not staged

• git diff --staged filename -- it will show staged changes in file


--- if same file is shown both in staged and un-staged area it
means some changes of the file are added to staging area and
some changes of the file are not added to staging area.

• git rm : it will remove from both working dir and local repo
• git rm --cached filename --- it will remove only from local
repo . it will exist in working dir

• vim .gitignore: this file will ignore the changes. in .gitignore


file we have to mention for which files we have to ignore
changes

• git reset filename --- this command is used to remove files


from staging area
Git Commands
• git commit --amend -m "message" --- this command will add new
message to latest commit

• git tag --a v1 commitid -m "message" --- this command will add tag to
commit id

• git tag : it will show no of tags

• git show tagname --- It will show changes made in that particular tag

• git revert commitid --- it will revert all changes in that particular commitid
Git Commands
• git reset --hard commitid : it will remove all changes made after this
commit id. and HEAD will point to this commit id. it is like
destructive command. once we do this again we cant get changes again

• git branch : it will show no of branches

• git checkout -b <New branchname> <present b.n.> --- it will create


new branch

• git log --oneline b1/B.N --- it will give commits of b1 branch

• git checkout master --- it will switch to master branch


Branching Strategy
• Master branch is the main branch- updated – no direct modifications
• Clone feature from matser branch- feature total code from master
• Do modifications in feature branch  merge master branch
• Dev environment –Dev servers
• Testing env(smoke testing, integration, UAT) –Test servers
• Pre Prod env- Pre Prod servers
• PROD- PROD servers
Git Commands

• git merge b1 --- it will merge b1 branch with master

• git branch -d <branch name> --- it will delete branch

• git branch -D <branch name> --- it will delete branch if it is fully not merged

• git rebase --- it will rewrite commit history. it will change the base of the

commit let us consider three commits A,B,C and new branch is created at B

commit and in new branch we will have A,B commits only if we need C

commit also in new branch with out merging, then we use rebase. if we use

rebase without merging we will get C commit also in same order


• git reset filename --- this command is used to remove files from
staging area

• git revert commitid --- it will revert all changes in that particular
commitid
Git Commands

• git stash --- Move the files for temporary storage

• git stash list --- it will list stash numbers

• git show stash number --- it will show what changes happend in that particular number

• Git stash apply – to apply stash

• Git stash drop stash number – to remove stash num from stash list

• git stash pop(apply+drop) <stashnumber> --- it will delete the stash and all files come
into working dir

• git stash clear --- it will clear all stashes

• git remote add origin <github repo URL> --- it will add remote repo

• git clone <github repo url> --- first time if we want to pull we have to clone
Steps to integrate git with github

• ssh-keygen -t ed25519 -C "gayazsheik7@gmail.com"


• eval "$(ssh-agent -s)"
• ssh-add ~/.ssh/id_ed25519
• tail ~/.ssh/id_ed25519.pub/cat ~/.ssh/id_ed25519.pub/clip
• Copy pub key in github
• Create Personal Access Token on GitHub - PAT

• From your GitHub account, go to Settings => Developer Settings => Personal
Access Token => Generate New Token (Give your password) => Fillup the
form => click Generate token => Copy the generated Token

• Now while pushing give this token at the time of password


• git push origin master
• git remote add b1https://github.com/gayazsheik7/dev-project1.git
• git remote add b1 https://github.com/gayazsheik7/dev-project1.git
• git push b1 master

• https://docs.github.com/en/github/authenticating-to-github/

connecting-to-github-with-ssh for adding ssh in github


Git Commands

• git push origin master --- it will push to remote repo

• git fetch origin master --- it will show the changes but it does not merge
the changes.

• Git pull will merge the changes. Pull=fetch+merge

• git cherrypic --- Cherry picking is nothing but choosing commit from
one branch and applying onto another branch

• git cherry-pick <commit-id> ---


• git branch : it will show no of branches

• git checkout -b <New branchname> <present b.n.> --- it will create


new branch

• git log --oneline b1/B.N --- it will give commits of b1 branch

• git checkout master --- it will switch to master branch


• git merge b1 --- it will merge b1 branch with master

• git branch -d <branch name> --- it will delete branch

• git branch -D <branch name> --- it will delete branch if it is fully not

merged

• https://docs.github.com/en/github/authenticating-to-github/connec
ting-to-github-with-ssh-

for adding ssh in github


• git remote add origin <github repo URL> --- it will add remote repo

• git clone <github repo url> --- first time if we want to pull we have to
clone

• git push origin master --- it will push to remote repo

• git fetch origin master --- it will show the changes but it does not
merge the changes. pull will merge the changes.

• Pull=fetch+merge
Git Interview questions
• 1. What is git/scm. – maintain different versions
• 2. Difference between Centralized VCS(SVN) and Distributed VCS(Git) – bitbucket,
subversion
• 3. Explain Git workflow – work dir/staging area/local repo+remote repo
• 4. What is gitclone command – first time if we need code in local from remote
• 5. What is the difference between git pull and git fetch – pull will show the changes
and merge the changes where as fetch will only show the changes
• 6. What is the difference between git clone and git pull -
• 7. What is git stash – it will move the uncommitted to temporary storage area
• Git stash list-
• 8. What is git merge – merging feature branch with master branch
• 9. Difference between git and github – git local repo and github is remote repo
• 10. What is merge conflict in git -
• 11. How to resolve merge conflicts-
• 12. What is git diff – will show the changes which are not staged
• 13. What is amend command – modify recent commit message
• 14. What is git reset command- it will remove files from staging area
• 15. what is difference between revert(commitid) and reset- revert will
undo the changes
• 16. What is git log – it will show all commit ids – git log --5
• 17. How to create repository in git – git init
• 18. What is git checkout – to change the branch
• 19. What is git branch –d <branch name> – it will remove the branch
• What are the environments you are having – DEV/SIT-UAT/PREPRO/PROD
• What branching strategy you are using –
• What is devops people role – creating branches , giving access to
branches, merging branchs, resolving merge conflicts.
• What is Git rebase-
Git Cherrypic:: it will move commitid from one branch to
another branch

git cherry-pick is a powerful command that enables


arbitrary Git commits to be picked by reference and
appended to the current working HEAD. Cherry picking is
the act of picking a commit from a branch and applying it to
another. git cherry-pick can be useful for undoing changes

Git cherrypic commitid

You might also like