- User name :
git config --global user.name "user name"
- User email :
git config --global user.email "userEmailID"
- User name :
git config --global user.name
- User email :
git config --global user.email
3. Cache login credentials (It helps to avoid re-typing the username and password everytime you perform a commit)
git config --global credential.helper cache
git clone URLofRepository
- Initialize git in existing folder :
git init
- Initialize git with new folder :
git init folderName
- Adding a single file :
git add fileName
- Adding all files :
git add .
git status
- Single line message :
git commit -m "Short summery about commit"
- Complete commit message :
git commit
- List of newest commits :
git log
- Detailed changes of each file :
git log -p
git show commitID
git show commitHash
- Unstaged changes :
git diff
- Staged changes :
git diff --staged
- Changes of a specific file :
git diff fileName
- Differences between two commit ids :
git diff commitId1 commitID2
- Remove a single file :
git rm fileName
orgit rm directoryName/fileName
- Remove files with a particular extension :
git rm *.extensionName
orgit rm directoryName/*.extensionName
- Remove file only from VCS :
git rm --cached fileName
orgit rm directoryName/fileName
Note : First two commands will also remove the files from the local system.
git mv oldFileName newFileName
git mv sourceDirectoryName/fileName destinationDirectoryName
Note : Executing the above command will move the source into the destination directory. The source must exists and can be a file, or a directory and the destination must be an existing directory.
- Restore a unstaged working tree files :
git checkout fileName
- Restore a staged working tree file :
git reset HEAD fileName
- Restore all staged files :
git reset HEAD
- Update the most recent commit :
git commit --amend -m "Updated message for the most recent commit."
- Commit more files to most recent commit :
git add fileName
thengit commit --amend --no-edit
git revert HEAD
git revert commitID
git revert commitHash
- Undo but preserve the changes locally :
git reset commitID
orgit reset commitHash
- Discard all the history and changes back to the specific commit :
git reset --hard commitID
orgit reset --hard commitHash
- Only create a new branch :
git branch newbranchName
- Create and switch to a new branch :
git checkout -b newBrachName
- List all branch :
git branch
- List all remote branches :
git branch -a
- Normally delete a branch :
git branch -d branchName
- Forcibly delete a branch :
git branch -D branchName
- Delete a remote branch :
git push origin --delete branchName
- Normally merge a branch :
git merge -d branchName
- Merge a branch with a merge commit :
git merge --no-ff branchName
- Commit log of current branch :
git log --graph --oneline --decorate
- Commit log of all branches :
git log --all --graph --oneline --decorate
Note : The
--graph
option will draw an ASCII graph, which represents the branch structure of the commit history. When it used in association with the--oneline
and--decorate
flags, it makes it easier to identify which commit belongs to which branch.
git merge --abort
- Origin repositories :
git remote add origin URLofRepository
- Upstream repositories :
git remote add upstream URLofRepository
git remote -v
- Origin repositories :
git remote show origin
- Upstream repositories :
git remote show upstream
git push origin branchNametobePushed
git pull
git pull --verbose
git merge origin
git push -u origin newBranchName
git push --delete origin branchName
git rebase branchName
Note : The above command will change the base of your branch from one commit to another, which will make it appear as if you have created your branch from a different commit.
git ls-files --others --ignored --exclude-standard
git stash
git stash pop
git stash list
git stash drop
- Remove untracked files :
git clean -f
- Remove untracked files/directories :
git clean -fd
- List all files/directories that would be removed :
git clean -nfd
git blame fileName