how to use github on ubuntu

1 Installing Git for Linux

Download and install Git for Linux :

sudo apt-get install git

 

2 Configuring GitHub

Once the installation has successfully completed, the next thing to do is to set up the configuration details of the GitHub user. To do this use the following two commands by replacing "user_name" with your GitHub username and replacing "email_id" with your email-id you used to create your GitHub account.

git config --global user.name "user_name"

git config --global user.email "email_id"

The following image shows an example for my configuration with my "user_name" being "akshaypai" and my "email_id" being "abc123@gmail.com"

 

3 Creating a local repository

Create a folder in your system. This will serve as a local repository which will later be pushed onto the GitHub website. Use the following command:

git init Mytest

If the repository is created successfully, then you will get the following line:

Initialized empty Git repository in /home/akshay/Mytest/.git/

This line may vary depending on your system.

So here, Mytest is the folder that is created and "init" makes the folder a GitHub repository. Change the directory to this newly created folder:

cd Mytest

 

At this time, you can use git clone command to copy the project you want, for instance:

git clone --recursive https://github.com/alecjacobson/nested_cages.git

4 Creating a README file to describe the repository

Now create a README file and enter some text like "this is a git setup on linux". The README file is generally used to describe what the repository contains or what the project is all about. Example:

gedit README

You can use any other text editors. I use gedit. The content of the README file will be:

This is a git repo

 

5 Adding repository files to an index

This is an important step. Here we add all the things that need to be pushed onto the website into an index. These things might be the text files or programs that you might add for the first time into the repository or it could be adding a file that already exists but with some changes (a newer version/updated version).

Here we already have the README file. So, lets create another file which contains a simple C program and call it sample.c. The contents of it will be:

 
#include<stdio.h>
int main()
{
printf("hello world");
return 0;
}

So, now that we have 2 files

README and sample.c

add it to the index by using the following 2 commands:

git add README

git add smaple.c

Note that the "git add" command can be used to add any number of files and folders to the index. Here, when I say index, what I am refering to is a buffer like space that stores the files/folders that have to be added into the Git repository.

6 Committing changes made to the index

Once all the files are added, we can commit it. This means that we have finalized what additions and/or changes have to be made and they are now ready to be uploaded onto our repository. Use the command :

git commit -m "some_message"

"some_message" in the above command can be any simple message like "my first commit" or "edit in readme", etc.

7 Creating a repository on GitHub

Create a repository on GitHub. Notice that the name of the repository should be the same as the repository's on the local system. In this case, it will be "Mytest". To do this login to your account on https://github.com. Then click on the "plus(+)" symbol at the top right corner of the page and select "create new repository". Fill the details as shown in the image below and click on "create repository" button.

Once this is created, we can push the contents of the local repository onto the GitHub repository in your profile. Connect to the repository on GitHub using the command:

Important Note: Make sure you replace 'user_name' and 'Mytest' in the path with your Github username and folder before running the command!

git remote add origin https://github.com/user_name/Mytest.git

 

8 Pushing files in local repository to GitHub repository

The final step is to push the local repository contents into the remote host repository (GitHub), by using the command:

git push origin master

Enter the login credentials [user_name and password] .

The following image shows the procedure from step 5 to step 8

So this adds all the contents of the Mytest folder (my local repository) to GitHub. For subsequent projects or for creating repositories, you can start off with step 3 directly. Finally, if you login to to your GitHub account and click on your Mytest repository, you can see that the 2 files README and sample.c have been uploaded and are visible to all as shown in the follwoing image.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值