Experiences in the community

Just another WordPress.com weblog

The Git way -III

This is part three of the Git basics or Git way for people.

Now as we have already covered setting up and everything, this part will be easy.

The first thing to do is to go to your gitorious.org page and Click on Add Project.

Give some name and some description.  Just for this example, I just made a project called Movies. While apart from having git repository for coding projects, you can make git repositories for anything. As I didn’t want to make it baby simple, I use the most simple kind of project I couhttps://flossexperiences.wordpress.com/2014/09/02/the-git-way-ii/ld think of, of having lists and using that to show how to do things.

Anyways, once you have put up some name and some description your repo. is almost complete and you will get something lhttps://flossexperiences.wordpress.com/2014/09/02/the-git-way-ii/ike this :-

Congratulations on your new repository!

Please follow these few steps to start using your new repository.
Install and configure Git

If you haven’t already, download and install Git. Then provide some basic configuration to Git:

git config –global user.name “Your full name”
git config –global user.email “shirishag75@gmail.com”

Create a new Git repository

If your project is not already using Git, initialize a repository now:

git init .

Add the existing files to Git’s index and commit:

git add .
git commit -m “Initial commit”

Push your changes

Configure your newly created Gitorious repository as a “remote”, then push your changes:

git remote add origin git@gitorious.org:movie-list/movie-list.git
git push -u origin master

The -u (–set-upstream) tells Git that your master branch always goes to the origin remote. Next time you can push by simply issuing:

git push

I am slightly old school so I always use git push origin master but as shared you can also use just git push.

Now the first thing to do is clone your repository to your local machine at some specific place. I use a directory called games where I usually put all my git directories, you can use whatever you like :-

~/games$ git clone git@gitorious.org:movie-list/movie-list.git

I made sure I am using the ssh/git way.

This is the output that comes :-

~/games$ git clone git@gitorious.org:movie-list/movie-list.git
Cloning into 'movie-list'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

IF you want you can do a listing and you will see that it’s indeed empty.

~/games/movie-list$ ls
~/games/movie-list$

As can be seen it’s an empty repository. So let’s populate it now :-

~/games/movie-list$ leafpad hindi-movies.txt

And add some content to that file. These are the movies I added :-

~/games/movie-list$ cat hindi-movies.txt
Salaam e-ishq
Barfi
3 Idiots
Taare Zameen Par
Swades

Once you are happy for now, you have to tell git that this is a file you want to add to your repository and it needs to be tracked, you do it by saying :-
~/games/movie-list$ git add hindi-movies.txt

This is also known as staging a file. You can also remove the file from staging by simply stating :-
~/games/movie-list$ git rm hindi-movies.txt

Once you have done that, you need to write some commit message. Commit messages are nothing but telling yourself and the world what you accomplished/changed in your code/list whatever it is you are doing. As your files become bigger it helps to keep track of when changes happen. Also if you have more than one person doing changes it will also help to track that as well. So commit messages are pretty important as they give a lot of clues as to what happened at any point of time.

~/games/movie-list$ git commit -m "Initial list of hindi movies"
[master (root-commit) 84b6edf] Initial list of hindi movies
1 file changed, 6 insertions(+)
create mode 100644 hindi-movies.txt

Once this is done you just to have push it up, as shared I like to have the whole path written so it’s :-

~/games/movie-list$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 303 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: => Syncing Gitorious... [OK]
To git@gitorious.org:movie-list/movie-list.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

Once this is done, you can check on the web at your repo. if that file is being shown or not.

As I have actually made the repo. you can check at https://gitorious.org/movie-list/movie-list/

I did the same thing again with english-movies as well just so the process is well understood.


~/games/movie-list$ nano english-movies.txt

~/games/movie-list$ git add english-movies.txt

~/games/movie-list$ git commit -m "adding initial english-movies list"
[master 3eec543] adding initial english-movies list
1 file changed, 4 insertions(+)
create mode 100644 english-movies.txt

~/games/movie-list$ git push origin master
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 347 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: => Syncing Gitorious... [OK]
To git@gitorious.org:movie-list/movie-list.git
84b6edf..3eec543 master -> master

That’s it you are adding files to your repository.

At any point of time you can always do a git status to see where you are :-

~/games/movie-list$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

The last part would be about forking repositories (making clones) and initiating pull requests to the original repo.

Till l8er.

Single Post Navigation

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

%d bloggers like this: