Tuesday 16 July 2019

Git: Push the changes to remote repository


In this post, I am going to explain how to push the changes to remote repository. There are 5 steps involved in pushing the content to remote repository.

a.   Clone the repository
b.   Update some files
c.    Add updated files to staging area
d.   Commit staged files to local git
e.   Push the changes to remote repository

Step 1: Clone the repository
Syntax
git clone {branch_url}
$git clone https://github.com/harikrishna553/gitHelloWorld.git
Cloning into 'gitHelloWorld'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 12 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), done.
$
$tree
.
└── gitHelloWorld
    ├── README.md
    └── welcome.txt

1 directory, 2 files

Step 2: Update some files
Navigate to gitHelloWorld folder and update welcome.txt file.


After updating welcome.txt file, execute ‘git status’ command, it shows that ‘welcome.txt’ file is in modified state.
$git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

 modified:   welcome.txt

no changes added to commit (use "git add" and/or "git commit -a")

Step 3: Add updated files to staging area.

Syntax

git add {file_name}
$git add welcome.txt 
$
$git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 modified:   welcome.txt

Step 4: Commit staged file to local git.

Syntax

git commit -m "Some Message"
$git commit -m "Updated welcome.txt file"
[master deb0c7c] Updated welcome.txt file
 1 file changed, 1 insertion(+)
$
$git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Step 5: Push changes to remote branch.

Syntax
git push origin {branch_name} 

Execute 'git branch' command to know in which branch you are in.

$git branch
* master


Execute ‘git push origin master’ to push the changes to remote master branch.

$git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 363 bytes | 363.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/harikrishna553/gitHelloWorld.git
   e875f74..deb0c7c  master -> master



Previous                                                    Next                                                    Home

No comments:

Post a Comment