Command
$ git config --global user.name "<username>"
$ git config --global user.email <email id>
Example
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
Command
$ git init
Note: Create a folder in your system and run this command to create a local repository.
Command
$ git clone <repository url>
Example
$ git clone https://github.com/srivatsa17/Git-commands.git
Command
$ git checkout -b <new branch> <existing branch>
$ git push <remote name> <new branch>
Example
$ git checkout -b development master
$ git push origin development
Command
$ git checkout <existing branch>
Example
$ git checkout development
Command
$ git branch
Command
$ git branch -a
Command
$ git push -all <remote name>
Example
$ git push -all origin
Command
$ git push -d <remote name> <branch name>
$ git branch -d <branch name>
Example
$ git push -d origin development
$ git branch -d development
Command
$ git add <filename>
Example
$ git add README.md
Command
$ git add *
Command
$ git commit -m "Commit message"
Example
$ git commit -m "First commit"
Command
$ git push <remote name> <branch name>
Example
$ git commit origin master
Note: If upstream branch is already configured, just run
$ git push
Command
$ git status
Command
$ git pull
Command
$ git merge <branch name>
Example
$ git merge development
If current branch is master, this will merge branch development into master.
Command
$ git diff
Command
$ git reset
Command
$ git stash
This command takes the uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.
Command
$ git stash pop
Command
$ git tag <tagname>
Example
$ git tag 2022.05
Command
$ git tag -l
Command
$ git remote
Command
$ git remote -v
Command
$ git log
Command
$ git log -p
Command
$ git revert <commit>
Example
$ git revert d8ed902ffe7c1529d02d9a4857c1f541e2e0ce27
Command
$ git commit --amend -m "New commit message"
Example
$ git commit --amend -m "Updated message"
Command
$ git grep <searchable string>
Example
$ git grep "foo()"
Command
$ git reflog
$ git reset --hard <commit ID>
git reflog
will give the list of commit hashID'sgit reset --hard <commit ID>
will only make changes in local repogit push --force
is required if changes has to be pushed to remote server
Example
$ git reset --hard 95377807
This will move our code into previous commit with ID 95377807
Command
$ git restore /path/to/folder
git restore .
will reset all the files to its original state
Command
$ git checkout <new branch where you need the commit>
$ git cherry-pick <commit hash>
$ git push
Example
$ git checkout master
$ git cherry-pick a885370
$ git push
Suppose i have branch development with commit hash a885370. I switch to branch master and use cherry pick command.