How to Push Local Git Repository to Remote Git Repository

Posted on

This article describes step by step taken for initializing a Local Git Repository where the main goal is for pushing source codes available locally to a Remote Git Repository.  Those steps are specified as follows :

1. Initialize a Local Git Repository.  Supposed there is a folder contained source code with files or folders.  And the source code comprise of files and folders will be pushed to a Remote Git Repository. So, in order to initialize the Local Git Repository below is the correct or the suitable command to be performed :

git init

Below is the example of the above command executed :

[user@hostname apps]$ git init
Initialized empty Git repository in /home/user/apps/.git/
[user@hostname apps]$

2. After that, add the existing files or folders located in the Local Git Repository by executing the following command :

git add .

Below is the example of the command execution above :

[user@hostname apps]$ git add .
[user@hostname apps]$

3. The command executed in the second step is adding all of the files into a staging area. The next step is to commit all files and folders from the staging area to the Local Git Repository folder.  Below is the command executed :

git commit -m "Commit Message"

The above command can be executed in a real example as follows :

[user@hostname app]# git commit -m "Initialize Project app"
[master (root-commit) 015ame9d1c] Initialize Project app
85 files changed, 5346 insertions(+)
create mode 100755 xxxxx.xxx
create mode 100755 xxxxxxxxx/xxxxx.xxx
...
...
...
[user@hostname app]#

4. After successfuly committing the files and folders located in the assumed source code folder named ‘app’ in this aticle context.  The next step is defining the Remote Git Repository as shown below :

git remote add origin remote_repository_URL

For further detail example, below is the execution of the above command for defining the Remote Git Repository Folder :

[user@hostname app]$ git remote add origin http://my.web.app.com/gitlab/user/app.git
[user@hostname app]$

5. So, after defining the Remote Git Repository Folder shown in the fourth step which is represented by an URL of ‘http://my.web.app.com/gitlab/user/app.git where it is actually a fake address chosen just to set an example, just push the source code . Push the source code by executing the following command so that the already committed files and folders inside the source folder named ‘app’ will be pushed. Below is the command executed :

git push origin master

The example is shown as follows :

[user@hostname app]# git push origin master
Username for 'http://my.web.app.com': user
Password for 'http://user@my.web.app.com':
Counting objects: 82, done.
Delta compression using up to 40 threads.
Compressing objects: 100% (79/79), done.
Writing objects: 100% (82/82), 6.51 MiB | 3.93 MiB/s, done.
Total 82 (delta 16), reused 0 (delta 0)
To http://my.web.app.com/gitlab/user/app.git
* [new branch] master -> master
[user@hostname app]#

As shown in the above output generated the operation for pushing the source code or files and folders located in the folder named ‘app’ has finally succeeded.

One thought on “How to Push Local Git Repository to Remote Git Repository

Leave a Reply