ROR Application Development Tips

I'm Ruby on Rails developer. I love to share my experience, technical knowledge. I work at Crypex Technologies which is developing applications in ROR for more than a decade.

GitHub - The Most Useful Code Committing Platform for Software Developers

When working in a team, you may have come across a situation wherein there are many copies of Code of your Ruby on Rails Application and then you really don't know if it has been updated,well-organized or well merged, for that matter, haven’t you?

 

Well, GitHub is your solution to the same.GitHub is a platform that I rely a lot on my coding. Be it organizing, updated code or merging code, this platform takes care of it all.

 

GitHub is a code hosting platform for version control and collaboration. It is a very useful tool that allows you to work from any geographical location.

 

GitHub is the most powerful platform for management and review of the code. Github is used for managing the code on the single platform. Using GitHub you can track the changes of each commit.

 

Github also provides public and private repositories. The public repository is most commonly used for open source software applications.

Let’s learn:

  • How to create a repository in a GitHub?
  • How to create new branches and manage these branches in  GitHub?
  • How to push your code in GitHub?
  • How to manage commits?
  • How to create and manage pull request GitHub?.

I’ll start considering you a RoR developer and then, of course, you know how to create your account in GitHub. Well, You should know that!

 

On Logging into GitHub, you’ll find many options and parameters but for a kick-start to committing codes in GitHub, first, you need to create a repository.

 

Create a repository in a GitHub :

 

The GitHub repository is a  virtual directory or space where we can access your project, its files, and all related data.

f:id:michaleleo432:20180809195550j:plain

 

On click of new repository button, you will be redirected to new directory form page. You need to follow the below steps to create a new repository in GitHub.

  1. Write a valid name for the repository
  2. Write a short and simple description of the project.
  3. Click on new repository button to submit the form for creating the repository.

 

f:id:michaleleo432:20180809195557j:plain



After successful submission of the form, you will be redirected to the Setup page of the created repository.

 

 

f:id:michaleleo432:20180809195609j:plain

First of all, take a clone for the projects, you need to make your backup is ready!. Use the following command.

 

git clone https://github.com/Test/sample-app.git

 

Then you need to change the directory

 

cd sample-app

 

If you want to create a new branch by command line and switch to that branch you can use the below command.

 

git checkout -b  NC-2018-06-charts-data

 

Your  branch name should be short and descriptive

 

You can also change the current working branch by using the below command.

git checkout  NC-2018-06-charts-data

 

Push the code:

 

Now, once whatever changes you have made in the file you can track by using the below command.

 

git status

 

The above commands will list out all of the changes in files.

 

You can also check what contents and lines have been modified by using the below command. It will list out the changes, the Green color will show the line added and the red color will show line removed

 

git diff “file_path”

 

If the files are ready to push you can add these files by using the below command.

git add “file_path”

 

You can also remove the file from your local system and the remote system.

First, you need to delete the files locally then after executing the command “git status” it will list out the files that have been removed locally, then you need to run.

git remove “file_path”

 

After adding all the files you can commit the code on the remote server.

git commit -m “The commit message”

 

After adding all the files you can push the code on a remote server by using the command.

git push origin Rs-2018-06-charts-data

Manage commits:

 

IF you have NOT pushed your changes to the remote repository and just committed the code and then you may want to remove the commit, use.

git reset HEAD~1

 

If you have pushed your changes and you may want to revert to the previous commit then you need to run the below command.

git revert HEAD

 

This command will revert/remove the last one commit/ change.

 

Create and manage pull request:

  

f:id:michaleleo432:20180809195619j:plain

 

First, you will have to take the fork of the repository then you can change in the code and commit the code.

 

On click, or pull request, you can send the pull request to the specified person. After getting the pull request you can click on Merge pull request. Your commits will be merged into the base branch.

 

So, now you know, how easily GitHub can manage the code -not depending on any locations!!