Git push pull commands – local repository to github

Push

Local repository to Github / cloud

Pull

Remote respository / github to Local repository

We will see details of how we can import or export local project to github using few git commands.

Installation

Download & Install git for your respective OS from here

Github account

Login to github.com or signup to create an account in Github

Create a new repository

  • Login | Repository tab | New and enter some name to your repository
  • Note the repository url

Git Push (Export local project to github)

In command prompt, navigate to your project folder
cd ecl_workspace/CoreJava/

Initialise local repository as git repository (this will create a .git file under your project folder)

git init

Add all the files that you want to export to github, this will stage the file to commit – indexing

git add .

You can see the files ready to push to github by status command

git status

Commit the files that you have staged above with some comment message

git commit -m "initial commit"

Now specify where in github you want to push – url of ur git repository, remember we have noted the url initially

git remote add origin <remote github url>

Now push the files to remote github repository, to master branch

git push -u origin master

Refresh your github repository to see all files that you pushed.

Note – While push, it will ask you the github username and password, enter one by one

Pushing extra files next time

Let’s say you have added some more files to your project, follow below to export to github

Navigate to the project folder and add

git add .

git status

git commit -m "added some more files"

git push origin master

No need to do git init and git remote add as this is required for a new local repository to push.

Git pull (from github to local repository)

Navigate to the local folder where you want to import

git clone <remote github url>

if any new files added in your remote repository, then you can pull to your local by

git pull origin master

Note : No need to provide again path the remote url.

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *