you can install git from here
to be sure that git has been installed you can use git --version
git config
-
git config --global user.name "(name)"usage: setting name for commits
example:git config --global user.name "Javad" -
git config --global user.email "(email)"usage: setting email address for commits
example:git config --global user.email "name@gmail.com"
git init
git init (repository name)usage: creating an empty local git repository
example:git init /home/javad/projects/chessGame
git clone
git clone (url)usage: to clone a repository into a newly created directory
example:git clone https://github.com/JavadZandiyeh/LearningGit
git add
-
git add (file name)usage: adding file to Staged area
example:git add testFile.html -
git add -Aorgit add *usage: adding all files to a Staged area
-
git add *.(file type)usage: adding all files (with this file type) to Staged area
example:git add *.java
git commit
-
git commitusage: committing all files which are in the Staged area
note: this command opens a text editor for you and you have to write your message on -
git commit -m "(your message)"usage: committing all files which are in the Staged area
example:git commit -m "Adding top menu bar"
git status
git log
git logusage: show the history of the current branch
git diff
-
git diff HEADusage: show all changes to tracked files
-
git diff --stagedusage: show changes to files in the Staged area
git reset
git reset (file name)usage: putting files (which are in the Staged area) into the Untracked area
example:git reset pict.png
git branch & git checkout & git merge
-
git branchusage: show all branches
-
git branch (name of branch)usage: creating a new branch by this name
example:git branch developer -
git branch -d (branch name)usage: deleting branch if exists
example:git branch -d developer -
git checkout (branch name)usage : changing branch
example:git checkout developer -
git checkout -b (branch name)usage: creating a new branch by this name and also changing your branch to this branch
example:git checkout -b GUI -
git merge (branch name)usage: merging this branch into the current branch
note: if you want to merge a branch into the master you have to checkout to the master branch and then use this command
example:git merge GUI
git remote
git remote add origin (url of repository)usage: connecting your local repository to the remote server by this url
example:git remote add origin https://github.com/JavadZandiyeh/LearningGit
git tag
-
git tagusage: show all tags
-
git tag -a (tag name) -m "(your message)"usage: creating a new tag for last commit
example :git tag -a version3.4 -m "this is version 3.4" -
git tag -a (tag name) (hash of commit) -m "(your message)"usage: creating a new tag for commit by this hash
example :git tag -a version3.1 729375b1d1eaad8a2fb559a2ce4fc8a70d52c74a -m "version 3.1 for unveiling"
git show
-
git show (hash of commit)usage: show changes of this commit
note: you can find the hash of commits bygit logcommand
example: git show 729375b1d1eaad8a2fb559a2ce4fc8a70d52c74a -
git show (name of tag)usage: show commits of this tag
example:git show problemForLogic
git push
-
git push origin (branch name)usage : pushing the local branch into the remote server(can be GitHub, GitLab or etc)
example:git push origin master -
git push origin --tagsusage: pushing all new tags into the remote server
-
git push origin (tag name)usage: pushing this tag into the remote server
example:git push origin version3.4
git pull
git pull origin (branch name)usage : pulling branch from remote server(can be GitHub, GitLab or etc) into the local branch
example:git pull origin logic
- README files : stackedit.io
- more about commands : git-scm.com/docs
