Pushing a file into an already created Github repository

 Initializing GIT 


[root@manager ~]# cd gitrepo
[root@manager gitrepo]# git init  #Initializing GIT
Initialized empty Git repository in /root/gitrepo/.git/
[root@manager gitrepo]# git status  #Checking GIT status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    GettingStarted
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       GettingStarted_update1.txt
no changes added to commit (use "git add" and/or "git commit -a")

#Adding the repository

 

[root@manager gitrepo]# git remote add origin https://github.com/shaan2212/learningdocker.git
[root@manager gitrepo]# git remote -v
origin  https://github.com/shaan2212/learningdocker.git (fetch)
origin  https://github.com/shaan2212/learningdocker.git (push)

#Staging & Committing the File

[root@manager gitrepo]# git add GettingStarted_update1.txt
[root@manager gitrepo]# git commit -m "updating GettingStarted file through cmdline"
# On branch master
nothing to commit, working directory clean
[root@manager gitrepo]# git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    GettingStarted
#
no changes added to commit (use "git add" and/or "git commit -a")

# Always recommended to run git pull before git push 

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.
 
[root@manager gitrepo]# git push origin master
Username for 'https://github.com': shaan2212
Password for 'https://shaan2212@github.com':
To https://github.com/shaan2212/learningdocker.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/shaan2212/learningdocker.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


[root@manager gitrepo]# git fetch origin master
warning: no common commits
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), done.
From https://github.com/shaan2212/learningdocker
 * branch            master     -> FETCH_HEAD
 


[root@manager gitrepo]# git pull origin master
From https://github.com/shaan2212/learningdocker
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 GettingStarted.txt      | 562 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 README.md               |   2 +
 docker_installation.txt | 475 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1039 insertions(+)
 create mode 100644 GettingStarted.txt
 create mode 100644 README.md
 create mode 100644 docker_installation.txt
[root@manager gitrepo]# ll
total 132
-rw-r--r--. 1 root root 31548 Dec  1 13:55 docker_installation.txt
-rw-r--r--. 1 root root 65340 Dec  1 13:42 GGettingStarted_update1.txt
-rw-r--r--. 1 root root 31825 Dec  1 13:55 GettingStarted.txt
-rw-r--r--. 1 root root    73 Dec  1 13:55 README.md

[root@manager gitrepo]# git push origin master
Username for 'https://github.com': shaan2212
Password for 'https://shaan2212@github.com':
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 299 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/shaan2212/learningdocker.git
   11fd5e1..d68f2ba  master -> master

[root@manager gitrepo]# git show
commit 11fd5e1ab20e3d8b286cb69cd406207c9cc07858
Merge: 95e6761 094bbaa
Author: Shantanu Mukherjee <yoursshaan2212@gmail.com>
Date:   Sun Dec 1 13:55:39 2019 -0500

    Merge branch 'master' of https://github.com/shaan2212/learningdocker





No comments:

Post a Comment

Installation of Jenkins on Linux and Deployment NGINX through Jenkins

Installation of Jenkins: [root@worker1 ~]# useradd -c "jenkins user" jenkins [root@worker1 ~]# passwd jenkins Changing passw...