We Make your Working Easy.
Usefull git and github commands
git version
To find out the version of git installed:
git –versiongit config
To set the name:
git config –global user.name “Mehdi Raeisi”To set the email:
git config –global user.email admin@mehdira.comTo see the configured name:
git config –global user.nameTo see the configured email:
git config –global user.emailTo see all settings:
git config –listgit 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.gitTo transfer the repository from github to the system, by specifying a new name:
git clone https://github.com/mehdira/git-crash-course.git newRepositoryNamegit add
To add a new or changed file to the stage:
git add myFileName.formatTo add all the files that have changed in the project to the stage:
git add . git add * git add -Agit rm
To delete the selected file in the stage:
git rm myFileName.formatgit reset
To return the changed file from stage to the state before git add or git rm:
git reset HEAD myFileName.formatgit 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 statusTo display git status in summary:
git status -sgit branch
To create a new branch:
git branch -M myBranchNameTo display branches in a repository:
git branchTo delete an existing branch:
git branch -D myBranchNamegit checkout
To switch between branches:
git checkout myBranchNameTo create a new branch and move to it:
git checkout -b myNewBranchNameTo revert to the original state in files that were merged by mistake:
git checkout -m fileName.formatgit remote
To see a list of remotes related to the repository:
git remoteTo remove a remote from the repository:
git remote rm remoteNameTo 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 masterThe 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 mainThis 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 stashTo see the list of stash files:
git stash listTo add a stash to a branch:
git stash applyWith 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 logTo see all the previous commits of the desired branch (starting from the last commit):
git log branchNameTo see all previous commits from all branches (starting from the last commit):
git log –allTo see all the previous commits resulting from merging branches (starting from the last commit):
git log –mergesgit whatchanged
To view the commit logs, it is recommended to use the git log command instead of this command:
git whatchangedgit shortlog
To see a summary of the git log command: and to know who worked on what:
git shortloggit 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 showgit merge
To merge the selected branch into the current branch:
git merge branchNameTo 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 –squashgit rebase
To merge two branches into one branch (its function is similar to git merge)
git rebase baseRebasing 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 startStep 2- Introducing a good commit to git:
git bisect good a123Step 3- Introducing a bad commit to git:
git bisect bad z123git cherry-pick
To select a commit from a branch and apply it to other branches:
git cherry-pick commitHashCodegit archive
To combine multiple files into a single file:
git archive –format zip HEAD > archive-HEAD.zipThe 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 –rebasegit 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 tagNameTags 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-taggit 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 branch2git citool
To have a graphical program to run git commands:
git citoolgit 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 cleanTo 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 falseHave 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.