Basic commands:
to check installed version
git --versionto set user name and email for current repo
git config user.name "Manish Mishra"
git config user.email "manishsmishra97@gmail.com"
to list the current configurations for a repo
git config --listfirst time to initialize a project (Run inside project Directory)
git initcheck status
git statusGit Add - > adds selected changes to staging area
git add file1 file2Commit without -m it will pop out editor for text message
git commit
git commit -m "Your Message"add all changes to stage at once
git add .add and commit simultaneously
git commit -a -m "message"to view details about a particular commit
git showto view commit history
git log
or
git log --onelinerename file
git mvremove file that is tracked
git rmremove a file that is not staged or committed (Untracked)
git clean -fdclone a repo
git clonepull a repro (pull = fetch + merge)
git pulladd repo link to the local repo
git remote add originAfter adding above , to push to a remote repo
git push origin
Undoing changes:
- it will undo all the changes which are done to the file that are unstaged/uncommited
it will revert the changes and reflect the changes per current HEAD
git restoreremove file from stage area
git restore --stagedrevert creates a new commit to undo the changes as per the commit hash provided
git revert
Git Diff:
-compares staging area and working directory
only show unsatged changes
git diff
git diffget difference between two commits
git diffwill list changes between tips of the two branch
git diff
Branching:
view existing branches in current repo
git branchshould not include spaces
just makes the branch
does not switch to the branch (Head does not change)
git branch
-checkout the branch
git checkout -b
or
git checkout
- to list remote tracking branch git branch -r
Merge
- switch to the main branch, and use below git merge e.g: if you want feature branch to be merged in main git checkout main git merge feature
based on the commit histories; after creation of the feature branch from main: there are multiple cases of merge:
Fast-Forward: simplest type
In this the feature branch have single of multiple commit since creating the branch while the master branch does not have any commit in that period.
cherry-pick:
merge particular feature from feature branch to be merged into master
git cherry-pick
Tags:
creates a tag and attached it to the current commit
git tagto tag a particular commit
git tagdelete tag
git tag -d
- push all tags
git push --tags
- single tag
git push origin
- get details of tag
git show
Top comments (0)