Git Workflow (Pushing and Pulling) (PART-2)
In this article,we will see Push Commits from Central Repository add content to the file then push to Central Repository.
Implementation Steps
- Create a new directory and Initialize as Git Local Repository.
- Connect your Local Repository to Central Repository (GitHub).
- Pull Commits from Central Repository.
- Add content to the file.
- Adding file to Staging Area.
- Commit the file into Local Repository.
- Push Commits to Central Repository.
- Verify files/commits in Central Repository.
- Go to Mumbai Region.
- Pull Commits from Central Repository.
- Add content to the file.
- Adding to Staging Area.
- Commit the file into Local Repository.
- Push Commits to Central Repository.
- Verify files/commits in Central Repository.
Step 1 :
Create a new directory and Initialize as Git Local Repository
Create a new directory “londongit”
1 2 3 |
[root@ip-172-31-30-41 ec2-user]# mkdir londongit [root@ip-172-31-30-41 ec2-user]# ls londongit |
Go inside the directory “mumbaigit” and initialize git repository
1 2 3 |
[root@ip-172-31-30-41 ec2-user]# cd londongit/ [root@ip-172-31-30-41 londongit]# git init Initialized empty Git repository in /home/ec2-user/londongit/.git/ |
To see the Local Repository
.git is the local repository.
By default,it will be hidden.(shouldn’t deleted)
Commits will be store in local repository (.git)
1 2 |
[root@ip-172-31-30-41 londongit]# ls -a . .. .git |
Step 2 :
Connect your Local Repository to Central Repository (GitHub)
1 2 |
[root@ip-172-31-30-41 londongit]# git remote add origin https://github.com/Ramesh-Ktexperts/centralgit.git [root@ip-172-31-30-41 londongit]# ls |
Step 3 :
Pull Commits from Central Repository
1 2 3 4 5 6 7 8 9 |
[root@ip-172-31-30-41 londongit]# git pull origin master remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (2/2), done. remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done. From https://github.com/Ramesh-Ktexperts/centralgit * branch master -> FETCH_HEAD * [new branch] master -> origin/master |
Verify the file (Code)
1 2 3 4 5 |
[root@ip-172-31-30-41 londongit]# ls myfile [root@ip-172-31-30-41 londongit]# cat myfile first line from mumbai second line from mumbai |
To see the list of commits
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@ip-172-31-30-41 londongit]# git log commit f7e5d55c9daaef9bcb9099062ccffb99b93879e1 (HEAD -> master, origin/master) Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Sat Dec 14 05:25:21 2019 +0000 2nd commit from mumbai commit cbb38f20f70e7443eea2c3daa54fb7ae7f264873 Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Fri Dec 13 17:34:33 2019 +0000 1st commit from mumbai |
Note
Whenever you pull the commit that will be there in work space,staging area and Local repository.
Step 4 :
Add content to the file
Add content to the file “myfile”
1 2 3 4 5 |
[root@ip-172-31-30-41 londongit]# vi myfile [root@ip-172-31-30-41 londongit]# cat myfile first line from mumbai second line from mumbai third line from london |
To see the status of git
1 2 3 4 5 6 7 8 9 |
[root@ip-172-31-30-41 londongit]# git status On branch 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: myfile no changes added to commit (use "git add" and/or "git commit -a") |
Step 5 :
Adding file to Staging Area
Add
Add file to Staging Area.
1 |
[root@ip-172-31-30-41 londongit]# git add . |
To see the status of git
1 2 3 4 5 6 |
[root@ip-172-31-30-41 londongit]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: myfile |
Step 6 :
Commit the file into Local Repository
Commit
1 2 3 |
[root@ip-172-31-30-41 londongit]# git commit -m "1st commit from london" [master 731a447] 1st commit from london 1 file changed, 1 insertion(+) |
To see the list of commits
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@ip-172-31-30-41 londongit]# git log commit 731a4475e861543eb38a79700f9838a766b1be39 (HEAD -> master) Author: Hanuma <hanuma.ktexperts@gmail.com> Date: Sat Dec 14 06:17:09 2019 +0000 1st commit from london commit f7e5d55c9daaef9bcb9099062ccffb99b93879e1 (origin/master) Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Sat Dec 14 05:25:21 2019 +0000 2nd commit from mumbai commit cbb38f20f70e7443eea2c3daa54fb7ae7f264873 Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Fri Dec 13 17:34:33 2019 +0000 1st commit from mumbai |
To see the data of latest commit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@ip-172-31-30-41 londongit]# git show 731a447 commit 731a4475e861543eb38a79700f9838a766b1be39 (HEAD -> master) Author: Hanuma <hanuma.ktexperts@gmail.com> Date: Sat Dec 14 06:17:09 2019 +0000 1st commit from london diff --git a/myfile b/myfile index f56241a..b3a52b0 100644 --- a/myfile +++ b/myfile @@ -1,2 +1,3 @@ first line from mumbai second line from mumbai +third line from london |
Step 7 :
Push Commits to Central Repository
1 2 3 4 5 6 7 8 9 |
[root@ip-172-31-30-41 londongit]# git push origin master Username for 'https://github.com': rameshatchala.ktexperts@gmail.com Password for 'https://rameshatchala.ktexperts@gmail.com@github.com': Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/Ramesh-Ktexperts/centralgit.git f7e5d55..731a447 master -> master |
Step 8 :
Verify files/commits in Central Repository
Go inside github and see the files/commits.
Here,we can see 3 commits and file which has latest commit message.
To see the data of file
Click on myfile to open.
We can see the data of file.
Step 9 :
Go to Mumbai Region
Step 10 :
Pull Commits from Central Repository
Verify content of file
1 2 3 4 5 |
[root@ip-172-31-43-80 mumbaigit]# ls myfile [root@ip-172-31-43-80 mumbaigit]# cat myfile first line from mumbai second line from mumbai |
Step 11 :
Pull Commits from Central Repository
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@ip-172-31-43-80 mumbaigit]# git pull origin master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/Ramesh-Ktexperts/centralgit * branch master -> FETCH_HEAD f7e5d55..731a447 master -> origin/master Updating f7e5d55..731a447 Fast-forward myfile | 1 + 1 file changed, 1 insertion(+) |
Verify content of file
1 2 3 4 5 6 |
[root@ip-172-31-43-80 mumbaigit]# ls myfile [root@ip-172-31-43-80 mumbaigit]# cat myfile first line from mumbai second line from mumbai third line from london |
To see the list of commits
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@ip-172-31-43-80 mumbaigit]# git log commit 731a4475e861543eb38a79700f9838a766b1be39 (HEAD -> master, origin/master) Author: Hanuma <hanuma.ktexperts@gmail.com> Date: Sat Dec 14 06:17:09 2019 +0000 1st commit from london commit f7e5d55c9daaef9bcb9099062ccffb99b93879e1 Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Sat Dec 14 05:25:21 2019 +0000 2nd commit from mumbai commit cbb38f20f70e7443eea2c3daa54fb7ae7f264873 Author: Ram <rameshatchala.ktexperts@gmail.com> Date: Fri Dec 13 17:34:33 2019 +0000 1st commit from mumbai |
Step 12 :
Add content to the file
1 2 3 4 5 6 |
[root@ip-172-31-43-80 mumbaigit]# vi myfile [root@ip-172-31-43-80 mumbaigit]# cat myfile first line from mumbai second line from mumbai third line from london fourth line from mumbai |
To see the status of git
1 2 3 4 5 6 7 8 9 10 11 |
[root@ip-172-31-43-80 mumbaigit]# 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: myfile no changes added to commit (use "git add" and/or "git commit -a") |
Step 13 :
Adding to Staging Area
Add
The file is Adding to staging area.
1 |
[root@ip-172-31-43-80 mumbaigit]# git add . |
To see the status of git
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@ip-172-31-43-80 mumbaigit]# 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: myfile Commit [root@ip-172-31-43-80 mumbaigit]# git commit -m "3rd commit from mumbai" [master c3406c4] 3rd commit from mumbai 1 file changed, 1 insertion(+) [root@ip-172-31-43-80 mumbaigit]# git log commit c3406c400598c9315afe52ce2c030f99559f5493 (HEAD -> master) Author: Ram <ram.ktexperts@gmail.com> Date: Sat Dec 14 06:30:34 2019 +0000 3rd commit from mumbai commit 731a4475e861543eb38a79700f9838a766b1be39 (origin/master) Author: Hanuma <hanuma.ktexperts@gmail.com> Date: Sat Dec 14 06:17:09 2019 +0000 1st commit from london commit f7e5d55c9daaef9bcb9099062ccffb99b93879e1 Author: Ram <ram.ktexperts@gmail.com> Date: Sat Dec 14 05:25:21 2019 +0000 2nd commit from mumbai commit cbb38f20f70e7443eea2c3daa54fb7ae7f264873 Author: Ram <ram.ktexperts@gmail.com> Date: Fri Dec 13 17:34:33 2019 +0000 1st commit from mumbai |
Step 14 :
Push Commits to Central Repository
1 2 3 4 5 6 7 8 9 |
[root@ip-172-31-43-80 mumbaigit]# git push origin master Username for 'https://github.com': rameshatchala.ktexperts@gmail.com Password for 'https://rameshatchala.ktexperts@gmail.com@github.com': Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 302 bytes | 302.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/Ramesh-Ktexperts/centralgit.git 731a447..c3406c4 master -> master |
Step 15 :
Verify files/commits in Central Repository
Go inside github and see the files/commits.
Here,we can see 4 commits and file which has latest commit message.
To see the data of file
Click on myfile to open.
We can see the data of file.
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates
KTEXPERTS is always active on below social media platforms.
Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform
Priya
Best learning platform for devops students
santhi
Usually I never comment but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man,Keep it up.