You are on page 1of 4

Local & Remote repos

View existing remote repositories

$ git remote

Clone Repository Locally

$ git clone github-repo-url

Git Status
$ git status

 Add a specific file to commit
$ git add filename

 Add untracked file to commit

$ git add .

 Add files of certain extension

$ git add *.html

 Excluding file from staging

Create .gitignore file in git repo home (in the same folder in which .git folder exists) and specify
names or patterns of the files that we don’t want to track on git.
$ touch .gitignore
Add the patterns/file names to exclude to this file.
You may add .gitignore to git.

 Automatically stage and commit tracked files

Untracked files are not committed
$ git commit –a –m ‘xyz’

Commit the files ?in staging?

 Specify the commit message
$ git commit –m message

 S

Commit Logs
$git log

Add Origin
$ git remote add origin repo-url

To add additional repositories

$ git remote add repo-name repo-url

Push the commits ?in staging? to repo

$ git push –u origin master

-u origin master is required only while pushing first time. Next time onwards `$ git push` is sufficient.

Create file in local

$ touch filename.extension
Pull the latest repo to local
$ git pull origin master

Fetch the latest branch

$git fetch origin
Pulls the latest data of the remote branch to the local disk. Does not perform merging.

Create a branch
$ git branch MyBranch

Switch to branch
$ git checkout MyBranch

When you switch to the particular branch the local folder contents change to resemble to the contents
of the switched branch.

To Merge branch

1. Checkout/switch to destination branch say master branch

$ git checkout master
2. Merge the source brance
$ git merge MyBranch


$ git stash
$ git stash list
$ git stash apply
$ git stash apply --index
$ git stash drop --index
$ git stash pop

Dealing with conflicts

$ git merge tool