- If you want to use Git, we have to install the Git package on our system:
- For Fedora distributions (RHEL/CentOS):
# yum install git
- For Debian distributions (Debian/Ubuntu):
# apt-get install git
- Configure your identity with Git because every Git commit uses this information, for example, the following commit has been done by User awsstar and email is awsstar@foo.com:
# git config --global user.name “awsstar”
# git config --global user.email “awsstar@foo.com”
- Check your settings. You will find the above username and email-id:
# git config --list
- Now, let's try to create a repository on GitHub:
- Hit www.github.com in your web browser and log in with your credentials
- Click on create New Repository
Then, we will get something like the following screenshot. We have to mention the Repository name and a Description of the repository. After that, we need to select Public or Private based on our requirements. When we opt for Public, then anyone can see your repository, but you pick who can commit; when you opt for Private, then you pick who can see and who can commit, meaning by default it won't be visible to anyone. After that, we have to initialize the README, where we can give a detailed description of the project and click on Create Repository:
- Once we have a repository, HelloWorld, then let's try to clone it to our local machine and some program files. Cloning a repository means creating a local copy of the repository and it can be done as follows:
root@awsstar:~# git clone https://github.com/awsstar/HelloWorld.git
Cloning into 'HelloWorld'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
Checking connectivity... done.
root@abae81a80866:~# ls
HelloWorld
root@awsstar:~# cd HelloWorld
root@awsstar:~/HelloWorld# ls
LICENSE README.md
root@awsstar:~/HelloWorld#
- We have the HelloWorld repository on our local machine. So, let's add index.html and push it back to the repository. Create a file, index.html, and write HelloWorld inside it:
root@awsstar:~/HelloWorld# echo '<h1> HelloWorld </h1>' > index.html
- The git status command checks the current status and reports whether there is anything left to commit or not:
root@awsstar:~/HelloWorld# git status
On branch masterYour branch is up-to-date with 'origin/master'.Untracked files: (use "git add <file>..." to include in what will be committed)
index.html
nothing added to commit but untracked files present (use "git add" to track)
- Now to add the changes to the repository, we have to enter this command:
root@awsstar:~/HelloWorld# git add .
- To store the current contents of the index in a new commit, along with a log message from the user describing the changes, we need to enter this command:
root@awsstar:~/HelloWorld# git commit -m "index.html added"
[master 7be5f57] index.html added 1 file changed, 1 insertion(+)
create mode 100644 index.html
- Push your local changes to the remote repository:
root@awsstar:~/HelloWorld# git push origin master
Username for 'https://github.com': awsstar
Password for 'https://awsstar@github.com':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 327 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/awsstar/HelloWorld.git
a0a82b2..7be5f57 master -> master
Here, we can see that index.html is now in our GitHub repository: