We Make your Working Easy.​

Usefull git and github commands

git   version


To find out the version of git installed:

git –version

git   config

To set the name:

git config –global user.name “Mehdi Raeisi”

To set the email:

git config –global user.email admin@mehdira.com

To see the configured name:

git config –global user.name

To see the configured email:

git config –global user.email

To see all settings:

git config –list

git   init


To create an empty repository

(The current folder is considered as repository.)
git init

To create an empty repository with the chosen name:

(The folder with the selected name is considered as repository.)
git init myRepositoryName

git   clone

To transfer the repository from github to the system:

git clone https://github.com/mehdira/git-crash-course.git

To transfer the repository from github to the system, by specifying a new name:

git clone https://github.com/mehdira/git-crash-course.git newRepositoryName

git   add

To add a new or changed file to the stage:

git add myFileName.format

To add all the files that have changed in the project to the stage:

git add . git add * git add -A

git   rm

To delete the selected file in the stage:

git rm myFileName.format

git   reset

To return the changed file from stage to the state before git add or git rm:

git reset HEAD myFileName.format

git   commit

To confirm the changes in the stage:

git commit -m “my about text”

To change and edit the message of the last commit:

git ommit –amend -m “new my about text”

git   status

To display the files being changed and the files in the stage area that have not been committed yet:

git status

To display git status in summary:

git status -s

git   branch

To create a new branch:

git branch -M myBranchName

To display branches in a repository:

git branch

To delete an existing branch:

git branch -D myBranchName

git   checkout

To switch between branches:

git checkout myBranchName

To create a new branch and move to it:

git checkout -b myNewBranchName

To revert to the original state in files that were merged by mistake:

git checkout -m fileName.format

git   remote

To see a list of remotes related to the repository:

git remote

To remove a remote from the repository:

git remote rm remoteName

To access the repository in github, remote is used:

git remote add remoteName url
-example:
git remote add origin https://github.com/mehdira3000/myGitPracticing3.git
  • origin: is the alias of the link. It means the original remote. (is a common name)
  • http://github.com/… .git: URL copied to github.com site

git   push

To transfer the project (repository) from the computer to github (using the remote command):

git push -u remoteName myBranchName
-example
git push -u origin master

To transfer the project (repository) from the computer to github (without using the remote command):

git push https://github.com/mehdira3000/myRepositoryName.git master

The source and git header must be set before using the git push command:

git push –set-upstream shortName branchName
-example:
git push –set-upstream origin featureBranch

git   pull

To get the changes from the repository in github:

git pull remoteName
-example:
git pull origin

git   fetch

To download changes from other team members from github:

git fetch git fetch origin main
This command downloads information about all commits, references, etc. Therefore, before applying these changes to your computer’s repository, you can review them.

git   stash

To temporarily save uncommitted edited files:

git stash

To see the list of stash files:

git stash list

To add a stash to a branch:

git stash apply
With the git stash apply and git stash pop commands, saved changes can be reapplied. Both commands will reapply the changes saved in the last stash. A stash apply re-applies the changes, while a stash pop removes the changes from the stash and re-applies them to the working version.

git   log

To see all the previous commits of the current branch (starting from the last commit):

git log

To see all the previous commits of the desired branch (starting from the last commit):

git log branchName

To see all previous commits from all branches (starting from the last commit):

git log –all

To see all the previous commits resulting from merging branches (starting from the last commit):

git log –merges

git   whatchanged

To view the commit logs, it is recommended to use the git log command instead of this command:

git whatchanged

git   shortlog

To see a summary of the git log command: and to know who worked on what:

git shortlog

git   show

To view the details of a specific commit:

git show commitHashCode
-example:
git show 1fa88e2e12cff9b0fa08bc5169c81739054cfa11

Compared to the git log command, the git show command displays details about a specific commit.

git show

git   merge

To merge the selected branch into the current branch:

git merge branchName

To merge or merge the selected branch in the current branch, with the condition that the commit history of the selected branch is not entered in the main branch:

git merge branchName –squash

git   rebase

To merge two branches into one branch (its function is similar to git merge)

git rebase base
Rebasing is the process of combining or moving a sequence of commits on top of a new base commit. git rebase is a linear merge process.

git   bisect

To find bad commits:

Step 1- Start work

git bisect start

Step 2- Introducing a good commit to git:

git bisect good a123

Step 3- Introducing a bad commit to git:

git bisect bad z123

git   cherry-pick

To select a commit from a branch and apply it to other branches:

git cherry-pick commitHashCode

git   archive

To combine multiple files into a single file:

git archive –format zip HEAD > archive-HEAD.zip
The git archive command combines multiple files into a single file. It is like the zip tool, that is, it can decompress files and give access to each file separately. Creates a zip file of the current revision.

When getting the codes with the git pull command, we usually have to run rebase (and not merge). This prevents multiple merges.

git pull –rebase

git   blame

To examine the contents of a file line by line and determine who made each change:

git blame myFileName.format
-example:
git blame index.html

git   tag

To create a new tag:

git tag -a tagName
Tags are useful in git and can be used for release management. tag can be considered like a branch without change. Its importance is much greater when it is published publicly.

git   verify

To check the gpg signature of commits: (GPG or GNU Privacy Guard)

git verify-commit
-example:
git verify-commit f309e6f3c44241dbf94b54c801e821d0b692d624

To confirm the tag:

git verify-tag

git   diff

To compare the working file with its version in git:

git diff HEAD filename.format
-example:
git diff HEAD index.html

To compare two branches:

git diff branch1   branch2

git   citool

To have a graphical program to run git commands:

git citool

git   mv

To rename a file in git:

git mv oldFileName.format    newFileName.format
-example:
git mv index.html    firstPage.html

git   help

For information and guidance on git commands:

git help gitCommand
-example:
git help push

git   clean

To remove files that have not yet been added to the repository with git add:

git clean

To set the default git ide:

git config –global core.editor myIDE
-example:
git config –global core.editor emacs

To create aliases for commonly used git commands:

git config –global alias.myAlias myGitCommand
-example:
git config –global alias.i init
By alias, we can define alias names for our frequently used commands and execute our commands with them.

To view Persian documents correctly in the git status command:

git config –global core.quotepath false

Have your Mobile Application

It has never been easier to have your mobile application by us.

Our Vision

We are proud of all our work yet these deserve a spot up-front.

Our hope is to asist you to achieve value through our producted softwares and applications.

We are expert technology and you are expert in your business, so we can help togheter by useing the knowledg of both fields to having the best product.

Together with you, we find the proper solution for our problem.