Version control system records changes to the file or set of files over time so that you can recall specific version later
The world's most popular version control system OR free and open source distributed version control system
pointer that refers to the current loactions on your repository
- Track changes across multiple files
- Compare versions of projects
- Time travel back to older versions
- revert to previous versions
- Collaborate and share changes
- Combine changes
Github is the service provider that hosts git repositories in the cloud
Note
Two ways we can interact with git termianal
and GUI
- git config --global user.name
"VedantC"
git config user.name
- git config --global user.email
[email protected]
git config user.email
ls
: see the directorycd <dir-name>
: move into the directorystart.
: opens windows popup in windows onlyls <folder-name>/
: see folder from the foldercls
orclear
: Clear the terminalpwd
: to see current directorycd..
: Move out from the directorymkdir <dir-name>
: Create directoryrm <file-name>
: remove filerm -rf <dir-name>
: remove directory
- Create git repository into workspace directory by running :-> git init command
- You can clone existing git repository from elsewhere : `git clone
git status
: Is used to see the status of files (untracked and tracked)in working and staging areagit add <file-name>
: add files to track(tracked and staged)git add -A
orgit add *
: add all new and changed files to the staging areagit restore --staged<file-name>
ORgit reset HEAD <file-name>'
untracked tracked files or un-stagedgit checkout <file-name>
:To discard changes in working directorygit commit "message to commit"
:commit the staged filegit commit –a –m “message”
: commit directly tracked files avoiding staginggit diff
: to see what you have changed in file (working directory not staged)git rm Readme.md
: Remove file from staging areagit mv rename_from rename_to
: renaming file
git log
: too see a history of commitgit log –oneline
: to see history of commit in one line.log –stat
: to see difference between file in each commit.show <commit-hash>
:it will show metadata and content changes
git commit –amend
: redo the first commitreset HEAD <file-name>
: it will reset file from staging area to working directory(file in staged area)git reset –hard
: branch head will move to the commitgit restore –staged <file-name>
: it will restore file from staging area to working directorygit restore <file-name>
: discard changes in working directorygit rebase –i <commit-hash>^
: it will drop particular commit and changes
git remote –v
: to see remote repository URLgit fetch <branch-name> Or git pull <branch-name>
: It will fetch the changes from remote repository.git remote rename <from> <to>
: it will rename remote repositorygit remote rm or remove <branch-name>
: remove repository.git push <branch-name>
: push the changes into GitHub repository.git switch -
: switch to previous repositorygit branch <branch-name>
: it will create new branch from existing.git switch –c <branch-name>
: it will create branch if not exist and switched to it.git branch –move <existing-branch-name> <new-branch-name>
: used to rename the existing branch.
git tag
: it will list the existing taggit tag –l “tag-name>”
: it will show the particular tag we have mentioned.git tag –a “tag-name” –m “commit-message”
: create annotated tag(all the information regarding tag )git tag <tag-name>
: Create lightweight tags(it will not store all the information)git push origin <tag-name>
: push the tag into branchgit tag –d <tag-name>
: delete the tag.
git diff
: will show the files which are still not at stagedgit diff –staged
: it will show the difference between files in the staging and latest versiongit diff <first-branch> <second-branch>
: it will show the difference between the two branches
git merge <branch-name>
: it will merge all the changes into feature branchgit rebase <branch-name>
: It will add the changes into next head
git stash
: it will keep the changes into feature branch without committing while switching to new feature branchgit stash pop
: it will delete the stashgit stash apply
: apply stash changes into the current branchgit stash list
: get list of all stashesgit stash apply stash@{2}
: It will apply particular list stash changesgit stash drop stash@{2}
: It will remove stash changesgit stash clear
: It will clear all stash list