Basic
git --version or git -v | check git installed version shortened |
Config
git config user.name git config user.email git config --global user.name git config --global user.email git config user.name [UserName] git config user.email [EmailId] git config --global user.name [UserName] git config --global user.email [EmailId] git config --global --replace-all user.name Debashish git config pull.rebase false git config pull.rebase true git config pull.ff only git config --global alias.st status git config --global pull.rebase false git config --global pull.rebase true git config --global pull.ff only | display configured user name display configured user email display globally configured user name display globally configured user email set user name in config set user email in config set user name globally in config set user email globally in config eliminate error during adding global username merge (the default strategy) Rebase fast-forward only configure st as alias for status merge (the default strategy) rebase fast-forward only |
Create a new repository
echo "# Git_V1" >> README.md git init git add README.md git commit -m "first commit" git branch -M master git remote add origin [SSH Path for RemoteRepositoryURL] git push -u origin master | Create and write a file README.md with content "# Git_V1" initialize directory for git add mark down file with name README add commit message rename the current branch to "master add remote repository using URL push changes to master |
Push an existing repository from local to remote
git remote add origin [SSH Path for RemoteRepositoryURL] git branch -M master git push -u origin master | add remote repository using URL rename the current branch to master push your local master branch to a remote repository named origin and set it as the upstream branch |
Clone a remote repository to local
git clone [SSH Path for RemoteRepositoryURL] git clone –branch [BranchName] [RepositoryURL] | Clone a repository from remote to local machine Clones a specific branch from a repository |
Operations
git init git init [Directory] git add [FileName] git add . git remote add origin [SSH Path for Remote Repo] git status git diff git diff --staged git commit -m "[Message]" git commit -a -m "[Message]" git mv [FileName] [New_FileName] git push -u origin master git push -d origin [BranchName] git pull origin master | initialize directory for git create a new git repository in the specified directory add given files to stage add all unchanged files to stage add repository to remote show status of changes (tracked and untracked) show difference between changes (modified vs unmodified) show difference between changes between staged and unstaged push changes to stage area push changes rename file push changes to master delete remote branch update local repo from remote master repo |
Undo/Delete
git rm [FileName] git rm --cached [FileName] git restore --staged [FileName] git reset [FileName] git reset git revert [CommitId from above comman] rm -rf .git | remove file and commit in stage stop tracking file changes back from stage area addback given staged file to unstage addback all staged files to unstage create a new commit that undoes the changes made by a previous commit. Delete .git file from repository |
Branch
git branch git branch [NewBranchName git branch --merged git branch --no-merged git checkout [ExistingBranchName] git checkout -b [NewBranchName] git checkout --[FileName] git checkout -f git switch -c [NewBranchName] git merge [BranchNameToMergeWithCurrentBranch] git branch -d [BranchName] | list out all branch create new branch already merged branches not merged branches switch to existing mentioned branch create new branch and switch to it revert to previous stage for that file revert to previous stage for all changes create new branch and switch to it Merge provided branch name to merge with current branch Delete Branch |
Stash
git stash -u git stash list git stash pop git stash apply git stash drop git stash clear | temporarily save changes in your working directory, including untracked files displays a list of all the stashed changes in your repository apply the most recent stashed changes back to your working directory and then remove that stash from the stash list reapply changes that you previously stashed with git stash Drop the most recent stash remove all stash entries from your stash list. This is a way to clean up your stash when you no longer need any of the stashed changes. |
Log
git log git log -p git log -2 git log -p -2 git log --stat git log --pretty=oneline git log --pretty=short git log --pretty=full git log --pretty=format:"%h git log --oneline | view the commit history of a Git repository in reverse chronological order (most recent first). log with changed details last two log last two logs with changed details show changed status show changes in one line and in shorter view show changes in short summary show changes in full detail log in pretty customized format (a-> author, e-> email) show changes in one line |
Log Pretty
git log --pretty=format:"%T -- %an" git log --pretty=format:"%H -- %an" git log --pretty=format:"%h -- %al" git log --pretty=format:"%h -- %ad" git log --pretty=format:"%h -- %ar" git log --pretty=format:"%h -- %at" git log --pretty=format:"%h -- %ai" git log --pretty=format:"%h -- %aI" git log --pretty=format:"%h -- %as" git log --since=2.days git log --since=2.weeks git log --since=2.months git log --author="[AuthorName]" git log --before="Fri Aug 7 21:07:21 2020" |
No comments:
Post a Comment
This is a User Friendly Blog.
Simple Interface and Simple Controls are used.
Post your comments so i can modify blog regarding your wish.