Git Commands
Git Commands
• Git Workflow:
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.
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 add .
• history
Git Commands
• git log
• git show ‘commit id’ --- it will show what changes made in that
particular commit
• git diff-- it will show the file modifications which are not staged
• 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
• git tag --a v1 commitid -m "message" --- this command will add tag to
commit id
• 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 -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
• git revert commitid --- it will revert all changes in that particular
commitid
Git Commands
• git show stash number --- it will show what changes happend in that particular number
• 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 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
• 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
•
• 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/
• git fetch origin master --- it will show the changes but it does not merge
the changes.
• git cherrypic --- Cherry picking is nothing but choosing commit from
one branch and applying onto another 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-
• git clone <github repo url> --- first time if we want to pull we have to
clone
• 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