Skip to content
Sajjad Rad edited this page Nov 4, 2015 · 3 revisions

You can find some useful git commands:

Start with Git

Add your information

run this command for add your full name:

git config --global user.name "YOUR_NAME"

and run this for add your email:

git config --global user.email YOUR_EMAIL

Initiate a git repo

cd to your project root directory and run:

git init

Clone a git repo

git clone [url]

Remote Git URL

Add remote git url to repo

cd to your project root directory and run:

git remote add origin [url]

Remove git url

cd to your project root directory and run:

git remote -v

Branches

Branch information

git status

Create a new branch

git checkout -b [branch name]

Switch to branch

git checkout [branch name]

Delete a branch

git branch -d [branch name]

Commits and files

Add all files to tracker

git add -A

Commit

git commit -m "Message"

Change branch without commit

sometimes you want to switch to another branch but your work is in progress and you don't want to commit changes.you can stash changes and switch to other branches and use stash again in future.

Stash changes

git stash

Get stash list

git stash list

Use stash

git stash apply stash@{ID}

or for apply last stash

git stash apply

Commit history

git log

Try last commit again

git commit --amend -m "Message"

Push and pull

Push to certain branch on origin

git push origin [branch-name]

Fetch and rebase

git pull --rebase origin [branch name]

Merge

Conflicts

For resolving conflicts you should run git merge tools.Kdiff3 is one of good merge tools.

git mergetool