Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Thursday, 8 May 2014

GIT BRANCHING AND SIMPLE MERGING COMMANDS


Branching

$git branch: git branch list your available branches.

The branch that you are currently working on will have a star next to it.
$ git branch
*master
This means that we have a 'master' branch and we are currently on it.
$git branch (branchname): Create a new branch.
$ git branch testing
$ git branch
* master
  testing
$ git checkout (branch name) : To switch to a branch.
$ git checkout testing
switched to branch 'testing' .
Simple Example:
$ ls
README hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ git commit -m 'added two files'
[master 8bd6d8b] added two files
2 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 more.txt
create mode 100644 test.txt
$ ls
README hello.rb more.txt test.txt
$ git checkout testing
Switched to branch 'testing'
$ ls
README hello.rb
So now we can see that when we switch to the 'testing' branch, our new files were removed. We could switch back to the 'master' branch and see them re-appear.
$ ls
README hello.rb
$ git checkout master
Switched to branch 'master'
$ ls
README hello.rb more.txt test.txt

$git checkout -b (branchname): Create and immediately switch to a branch.

$git branch -d (branchname): Delete a branch
EX: $git branch -d testing
$git branch
master *
Note: Here testing branch has been removed.
$ git push origin <name_of_your_new_branch>:Push the branch on github.



Merging


Simple Example:
$ git branch
* master
$ ls
README hello.rb more.txt test.txt
$ git checkout -b removals
Switched to a new branch 'removals'
$ git rm more.txt
rm 'more.txt'
$ git rm test.txt
rm 'test.txt'
$ ls
README hello.rb
$ git commit -am 'removed useless files'
[removals 8f7c949] removed useless files
2 files changed, 0 insertions(+), 2 deletions(-)
delete mode 100644 more.txt
delete mode 100644 test.txt
$ git checkout master
Switched to branch 'master'
$ ls
README hello.rb more.txt test.txt
Once you have work isolated in a branch, you will eventually want to incorporate it into your main branch. You can merge any branch into your current branch with the git merge command. Let's take as a simple example the 'removals' branch from above. If we create a branch and remove files in it and commit our removals to that branch, it is isolated from our main ('master', in this case) branch. To include those deletions in your 'master' branch, you can just merge in the 'removals' branch.
$ git branch
* master
removals
$ ls
README hello.rb more.txt test.txt
$ git merge removals
Updating 8bd6d8b..8f7c949
Fast-forward
more.txt | 1 -
test.txt | 1 -
2 files changed, 0 insertions(+), 2 deletions(-)
delete mode 100644 more.txt
delete mode 100644 test.txt
$ ls
README hello.rb


***************ALL THE BEST*********************

HOW TO PUSH A SIMPLE APPLICATION IN TO GITHUB

  HOW TO PUSH A SIMPLE APPLICATION INTO GITHUB

Step 1: First create a new rails application in your local system.
EX: I was created one application in projrcts folder i.e, ~/projects/deviseauth
Step 2: Open the terminal and go to your application location.
ctrl+alt+t -------> To open the terminal
@ubuntu:~$cd projects
@ubuntu:~/projects$ cd deviseauth
Step 3: Initialize empty git repository.
@ubuntu:~/projects/deviseauth$ git init
you will see fallowing text on terminal.
Initialized empty Git repositoryin ~/projects/deviseauth/.git/
Step 4: To add all subsequent resources(on which you have made changes) under that folder to GIT's version control for commit.
@ubuntu:~/projects/deviseauth$ git add.
Step 5: To commit all the changes
syntax: $ git commit -m "simple message"
@ubuntu:~/projects/deviseauth$ git commit -m "new rails app"
Step 6:Go to your github account and create a new repositary give a name here my repositary name is “deviseauth”.
Step 7:
Syntax: $ git remote add [any name] [ path of remote repo]
git remote add is to add a "short name", such as origin, and it can be any name as well, which is like an alias to a URL. And origin is the usual path of where the remote repo points to.
@ubuntu:~/projects/deviseauth$ git remote add origin https://github.com/sarithachakilala/deviseauth.git
Step 8:To push your application to github
@ubuntu:~/projects/deviseauth$ git push -u origin master
It will ask your github account username and password.
[Note: The push operation is performed when the total work of your remote contains locally otherwise it gives fallowing error message. Error:failed to push some refs to 'https://github.com/sarithachakilala/deviseau hint: Updates were rejected because the remote contains work that you do nt have locally.]
At that time you need to perform step 9.
Step 9:Pull your remote work to your local application.
@ubuntu:~/projects/deviseauth$ git pull origin master
Step 10: Then try to perform push operation using step 8. It will works fine.


*********************HAPPY RAILS CODING****************

Wednesday, 7 May 2014

SETUP GITHUB IN UBUNTU


Setup Github in Ubuntu

  It is a new hosted Git repository service that's being called a "social network" for programmers. It is basically a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Step1 : You have to create your account at github and now you want to work with it from your terminal.
Step2 : (Setting up ssh keys)
Before you start installing Github, you should set up ssh keys:
 $cd ~/.ssh
If it says "bash: cd: ./.ssh:No such file or directory",it means its not generated and you should continue with step 3. But if it changes to ~/.ssh directory, continue from step 4. 
Step3 : open your terminal and type PRE.ctl { font-family: "Lohit Hindi",monospace; }P { margin-bottom: 0.21cm; }A:link  
   $ssh-keygen -t rsa -C "your_email@youremail.com"
You will get following lines: 'Generating public/private rsa key pair. Enter file in which to save the key(/Home/ubuntu/.ssh/id_rsa):' just press enter now it will ask you to enter passphrase note that passphrase you enter must be >4, otherwise you will have to repeat whole process again.
Ex:I enter here my name...saritha
Step4 : open the file id_rsa.pub from ~/.ssh/id_rsa.pub and copy whole content of that file.(or)
you can open that file from terminal by using command as
$gedit id_rsa.pub
copy whole data...(or)
copy it to the clipboard by usinning fallowing commands:$sudo apt-get install xclip
$xclip -sel clip < ~/.ssh/id_rsa.pub
Step5 : After copy of entire content. Open github site and login. go to “Account Settings” > Click “SSH Public Keys” > Click “Add another public key” paste it  into "key field" and title enter any title name. then press Add key.
Ex: Here I entered title name as SSH FOR UBUNTU.
Step6:
And now try to connect to github to see if everything is working:
$ssh-add ~/.ssh/id_rsa (here need to press enter)
$ssh git@github.com

It will ask per passwrd need to  type your password ( for the first time).
Step7:   (To configure git)
Now you have successfully setup ssh key and ready to install github in terminal.
to download a local copy of your code branch. You'll need to replace "username" with your GitHub user name and project name with the name of project on github.
Setup git with your name and email address
$git config --global user.name "Name Last Name"
$git config --global user.email "your_email@youremail.com"
$git config --global github.user your_username







*************HAPPY READING :-)******************