In this article we
will see how we can configure our local repository to connect to the Git hub
remote repository and push our code to the remote repository.
1) Initialize a Git
repository using "git init"
2) Now create a
couple of files. add and commit to the local repository
[root@vx111a
Mytest]# git add ReadMe
[root@vx111a
Mytest]# git add Hai.java
[root@vx111a
Mytest]# cat hai.java
public class hai {
public static void main(String st[]) {
System.out.println("This Is Git
Sample");
}
}
[root@vx111a
Mytest]# git commit -m "testing GIT"
[master
(root-commit) bad4374] testing GIT
2 files changed, 6 insertions(+)
create mode 100644 Hai.java
create mode 100644 ReadMe
3) Once the files
are added to the local repository we need to add these files to the remote
repository but before that we need to add the remote repository details to the
Git configuration.
check the remote
repository configured for the local repository using,
[root@vx111a
Mytest]# git remote show origin
* remote origin
Fetch URL:
https://github.com/jagadish12/MyTest.git
Push
URL: https://github.com/jagadish12/MyTest.git
HEAD branch: master
Remote branch:
master tracked
Local ref configured for 'git push':
master pushes to master (up to date)
or we can also use,
[root@vx111a
Mytest]# git config --get remote.origin.url
https://github.com/jagadish12/MyTest.git
The remote origin
is already configured over here , but if that is not configured we dont see the
above details.
For adding the
remote configuration details, we can use
git remote add
origin https://github.com/jagadish12/SampleTest.git
This will add the
remote configuration information. Once the remote configuration is added, we
can then push our local code committed to the remote repository using,
[root@vx111a
Mytest]# git push origin master
Username for
'https://github.com': jagadish12
Password for
'https://jagadish12@github.com':
Counting objects:
3, done.
Delta compression
using up to 8 threads.
Compressing
objects: 100% (2/2), done.
Writing objects:
100% (2/2), 274 bytes | 0 bytes/s, done.
Total 2 (delta 0),
reused 0 (delta 0)
To
https://github.com/jagadish12/MyTest.git
bad4374..089a50e master -> master
The git Push asks
for the Github User name and password for pushing the data to the remote
location ( aka remote repository )
Now we can login to
the Git Hub and check the updated file changes in the repository that we
created.
Now if we want to
remote the remote repository configured for a Git, we can use
[root@vx111a test]#
git remote remove origin
[root@vx111a test]#
git remote add origin https://github.com/jagadish12/SampleTest.git
More to Come
No comments :
Post a Comment