How to collaborate with Git?

Creating and learning becomes more interesting and worthy when people around the globe too contribute and share their ideas and technologies. This would also provide a space were they can store lines of code, projects or even other information. This platform is excellently staged by Git. Git is the right place that you can collaborate your works, sharing your ideas into various projects and works of others as well as getting better ideas from others so as to innovate technologically developed and efficiently working products. So its really important to have a deep insight into Git and well verse to manage with one’s workspace namely, a repository.

git2

Getting to the core, Git is a free and open source Version control system. It helps to handle small to large projects with speed and efficiency.It has many features like cloning,local branching, merging several contributions, giving pull requests etc. It is really a space to store content. Apart from the remote repository one has in git, it also provides a local repository in one’s computer on which a person can work on. It is generally a distributed VCS as the changes made in the code or project occurs in computers all the developers working on it.

SETTING UP GIT

So let’s get started with installation of Git.It can be easily installed usig the following lines of command.

  • For Ubuntu (debian based OS), use:                index.png
$ sudo apt install git-all
  • For macOS:

Checkout this site: http://git-scm.com/download/mac.

Now you can check the version of git through your terminal, using the command:

git --version

Now its all set to make through to the Git world.

CREATING A REPOSITORY

1.png

After getting Git installed the main task is to create a repository and get initialized to it. Git repository is a virtual storage space which you can access at any later time.You can give a description for the repo and also the programming language for the projects and codes that would be pushed into thst repo. Or you can clone an existing repository from elsewhere.

For creating a new repository, follow the steps below:

  • Either create a new folder of choose any of the local directories in your computer.
  • Get into that directory using:
cd /path/to/your/existing/code
  • Initialiseinto that directory using:
git init

For cloning into any existing repository, follow the steps below:

  • Fork the repository that you wanted to clone.(This creates a copy of the repository that you wanted to work on).
  • Clone the repo using the the url given using the command:
git clone <repo url>
  • Get into the repository that was cloned using the command:
cd /path/to/your/existing/code

Next, you can work in the cloned or created repository and make changes or new projects in it.

PUSHING A FILE INTO GIT

2

After making required changes in the local repository, these changes has to be updated into the remote repository, which can be done by the process of pushing the code into the repository.This includes several steps like:

  • Staging- Adding the committed changes and to keep track of all changes.
git add example.txt

For adding mutiple files do the following:

git add file1 file2 file3

  • Commiting- Commit is a change done to a local repository. It should be given a commit message signifying the commit done.
git commit -m "Commit Message"
  • Pushing- This pushes all the changes made in the local repository into the remote repository.

It is done as follows:

git push origin master

BRANCHES AND REMOTES

A branch serve as an independent abstraction for git operations like edit/commit/stage etc.The git branch command is used to create, rename, or delete branches.The main branch for a repository is mostly master branch or development branch. We can create several branches from this branches and work on it.Some commands related to branches are:

git branch         \\lists all branches in the repository.
git checkout -b <branchname>     \\Checkouts the current branch and                     switches to the new branch.
git branch -D <branch>            \\deletes the branch
A remote is like a common repository that all members working on it can use to exchange or share ideas.Collaborating with others involves managing these remote repositories. The following are some commands using remote:
git remote -v            \\lists all the remote present
#button {
    font-weight: bold;
    bor

PULL REQUESTS

pull

They are the features that provide a user-friendly interface for viewing proposed changes before integrating them into the main project.When you work on a different repository in Git and make certain changes in it, you have to let the collaborator know about the changes so as to let them merge your changes into the original repository. When the pull requests are open we can compare the changes between your branch and the remote branch and if there are no conflicts, you can send the PR. This is helpful well many developers are working on a single project parallely . While creating a PR, you can create a summary of the proposed changes.Once the pull request is created, the committed file undergoes certain checks which sees for anything which harms the already existing codes.

pull-request-workflow

Once you push a code into your repository, go to the repository page and and click on ‘Create new pull request’. Pick up the branch to which you have to push the request and the branch from which you want to push. Add a title and a description for the PR. Then click on Create pull request which makes the process done.

GIT REBASE 

Rebasing is the process of combining a sequence of commits to a new commit. This is used mainly so as to make a branch even with the master branch of the original repository. This can be explained taking a situation where the master branch had progressed certain commits forward compared to the feature branch by the time you are working on it. This makes the feature branch to be certain commits behinf the master branch. Git rebase can be used so as to seem that you have been working from the branch that have been even with the master branch. Hence there are 2 ways of merging, either by direct merging which would lead to conflicts or by rebasing and then merging which would make the branch look clean. Hence rebasing helps to integrate the upstream changes with the local repository.

The steps of rebasing are as follows:

  • Checkout the feature branch:
$ git checkout <branch>
  • Rebase the feature branch to the mater branch
git rebase master

GIT SQUASH

hand-squashing-empty-plastic-bottle-hand-crushing-plastic-water-bottle-against-single-use-plastic-120185276.jpg

It is the method of consolidating multiple commits made by a branch into a single commit before pushing into git.It is a manner of picking several commits and squashing them into one.The steps of squashing are as follows:

  • Rebase the feature branch as this shows all the commits done in that branch.
git rebase -i master
  • This shows something like:
pick fb554f5 This is commit 1
pick 2bd1903 This is commit 2
pick d987ebf This is commit 3
  • Edit all the “pick” tags except the first one to “squash”.
  • This looks something like:
pick fb554f5 This is commit 1
squash 2bd1903 This is commit 2
squash d987ebf This is commit 3
  • Save the editor give a commit message and close it.
  • Force push this into the feature branch.
git push -f origin <featureBranch>

This would squash all the previous multiple commits into one.

GIT RESET

It is a complex command of undoing certain local changes like undoing addition of some files etc.

For example:

$ git add abc.java       //will add a file named abc

$ git reset abc.java     //will remove the added filed named abc.

There are 4 ways of using reset command. They are:

  • –hard: It rsests the whole commit. By using this all  the local changes gets removed.Hence be very careful using this as it would probably clear all the local changes made so far.

git reset --hard

  • –mixed: This is the default one. It rests the staged files,but the working tree is not affected. Any difference between original commit and reset ones will be shown as untracked files.

git reset --mixed

  • –soft: It does not affect the added files or the working tree. It is almost similar with –medium except that the changes show as the changes to be committed.

git reset --soft

  • –merge: It is the recently added one. It helps to abort a failed merge.It resets the added files and the files affected by the merge.

git reset --merge

GIT STASHING

This is a command where your uncommitted changes are stored in some other space and can be reverted back to the branch. In this all changes whether staged or unstaged will be saved, unless it is committed.This helps in freely making other changes and commits and apply the stashed changes when required.This is also useful when you have to apply same changes for different branches.

The steps of stashing are as follows:

  • Check status to confirm that the changes are not committed.
$ git status
  • Stash the changes.
$ git stash

For Unstashing,

  • Pop the stash to reapply the changes to the current branch.
$ git stash pop

Inorder to give a proper idea of the stash we can make it descriptive by using the following command:

 git stash save "description"

These steps would help to stash the changes and work with ease.

images

The above are the important terms that one may use in Git. All these would help to collaborate projects integrating the contributions from around the world.

Advertisements

Babysteps into Java.

Lets get started peeping into what Java really is.Java is a programming language that creates several softwares. The compiled codes are known as Bytecodes.Java is much similar to C++ and C languages. This has a great hand in android and app development.                    what-is-java-000As i stepped into Amrita, particularly CSE, i kept thinking of peeping into coding and learning lots in programming. I knew that it was not like blinking an eye. But i had the patience and strong dezire as i was a begginer. I have also been thinking a lot about android development and app development. Seeing my parts of interests in my bio, one of my senior, Abhilash G (Java and Android developer), talked to me and sketched my dezire. He helped me a lot and gave me excellent introduction on android development.                            Android-Developers-Logo.png This made me step into Java. I was totally new to it. I googled more about it and also surfed through java documentation. Finally, i took my fingers vibrate to code the basic program in java, “Hello World program”. I have written my experience in java in this blog. Hope you all enjoy it.

After reading and surfing a lot, i started my works. I did not have Java in my in linux. So i installed java 10 in it. Then i wanted an editor to write the code. In this i was a bit confused. I saw many editors like Pico, Atom etc, while i was fogged with just Gedit and Vim. So in installed Atom and installed the script package in it. Then with the help of my senior i learnt about each command and parameters in it.

It was really different from python which i initially knew. I learnt that we use “class” defenition and it is assigned a name. Every code in java begins with a class command.A class includes Modifiers (public/protected/private) , a Class name, Key words and the Class Body which is within curly braces. Public, the commonly used one exposes a class to other classes too. While private hides from other classes. Then we write a name for the class. There are 50 keywords in java. Being the key words they cannot be used as variable names.Then comes the main body of the program.

Coming to the second line of code. This line has a main method and its signature is as follows:

                         public static void main(String[] arg)

The  main method gives the Main part of the program. It includes the string and the argument given by “argv” or “args”.The next step is to give the output. This has the following signature:

                        System.out.println("Hello World!!");

The program now gives the output. We can also give certain comments for the code wherever required. this can be done by the following way

 /** this is my HelloWorld program in java. I am a learner in java.*/

 

There are certain thing that one has to keep in mind while saving the java file. Its recommended to save the file in the same name as that of the class followed by .java signature.I have done my code using Atom editor.Screenshot from 2018-11-09 17-36-51.JPG

This experience of java was really thrilling and good. This becomes much more interesting when you have such a good guidance as i got from my senior mentioned above. And it is real fun to write and learn the codes in Java.

Completing my Foss Task!!!

Stepping first into Amrita, i was a bit scared about computing and programming as i was new to this.But it have all been so different when i joined the foss workshop.Even  academic portions had been more clear and i had a good picture of every single algorithm done in class just because of Foss workshop, particularly the efficient seniors, has nourished us well through their training. I also found that python is really cool and interesting to the core.

python-Programming-Language-Software.jpg

At first when i used to get questions, i felt nervous and did’nt know where to start with.But as the tasks were uploaded, i was all set to peep into it. As i saw the question i felt confident and just started it.As i did it, i got pretty good flow to move forward to the next step. At first i thought that it might mess up. But the logics that lit up  just because of the proper training of the workshop, helped me to do it. It was really an amazing time to do it. I did the Task, “Rock, Paper, Scissor”. It was thrilling and i really enjoyed it.At first i just made out the logics. Then i modified it in a user friendly manner. Then it was very interesting to do the github activities. For this i created a new repository of mine in name “fosstask”. It was a really good experience and i am eagerly waiting and hoping that i will go through the screening tasks and interviews. The link to my repository through which u can access the code for the ever interesting game “Rock Paper Scissor” is given below:

https://github.com/hsymphonyk/fosstask/blob/master/task1.py1*5TRuG7tG0KrZJXKoFtHlSg.jpegfoss

Myself here!!!

photo of person holding green leaf

I am so amazed to let you all view my ideas. Just feeling happy to share with the world my ideas of life and taking in the soothing fragrance of nature. The aspect of life to me is “a thing that makes each little being engaged with enthusiastic expectations.” The elixir of life is a charming soul that connects and sings along the rhythm of nature. So I wanted to connect all young souls, no matter how much it counts on you biologically, to the vibrant green glowing touch of nature.

Photo by Daria Shevtsova on Pexels.com