Getting Started with git

Summary:

  • Setup
  • Create your first repository and push
  • Commit and push
  • Remote Origin
  • Branching
  • Logging and navigating history

Setup

Local configuration

Local configuration means that your attributes are applicable only within your repository. Configure your username and email using following commands,


git config --local user.name "zillani"

git config --local user.email "shaikzillani@gmail.com"

View: Verify if name and email are set using the following commands, this would print the configured username and email


git config --local user.name

git config --local user.email

Global configuration:

Local configuration means that these variable are applicable for all the git repos on your system by default.


git config --global user.name "zillani"

git config --global user.email "shaikzillani@gmail.com"

This could have also be set by editing .GITCONFIG file located in your root directory, Example for windows: C:\Users\lenovo


[user]

email = shaikzillani@gmail.com
name = zillani

Creating your first Repo and Pushing:

Imagine that you have an empty repository on github.com, whose url is https://github.com/zillani/simpleApp.git, now you have some basic template of your app that you want to push to server, here’s what you would need to do,


git init

git remote add origin "https://github.com/zillani/simpleApp.git"

git add .

git commit -m "initial commit"

git push -f origin master

Note: origin is just a word, you can use any other word say stash-origin or any word

Commit and push


git add .

git commit -m "Added logger"

git push origin master

Remote Origin


git remote -v - Display remote origins

git remote remove origin - Deletes origin

git add remote origin https://github.com/zillani/simple-service-app.git - Adds Remote origin

[Note: origin is just a keyword, any other keyword can also be used]

Branching

View branch


git branch -l
git branch -r

Creating new branch


git checkout -b dev

Shifting

Shift to existing other branch say from ‘master’ to ‘dev’


git checkout dev

Merging branches

Merging dev into master, checkout to master branch and


git merge dev

Deleting a branch

Locally, say deleting dev branch


git delete -d dev

Remote branch,


git push origin :dev

Logging and Navigating history

Check your logs

git log

Check your changes

git status

Navigate back to some old commit

use the SHA1 code of the log, using git log and copy some portion on the SHA1 of the commit and give as below

git checkout u8jedfy667h6359ah77
Advertisements
Getting Started with git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s