Thursday 9 November 2017

Add specific file or project to github


Here I will discuss how to add project in github.


First we have to install gitbash

download url: https://git-scm.com/download/win

Install file by using all default option n press next, next.

Suppose this is my page

url: https://github.com/asifaftab87/java-core


I want to add my project or file to this repository.
For this we have copy download link


Now I want to add First.java file to my repository whose url is:

https://github.com/asifaftab87/java-core.git


I will go to first my folder which has First.java file


In this folder we will open git bash by right click shown below



once we click on Git Bash Here option then one terminal will open like this


So our git bash terminal is ready to execute our command.

Now we will execute our command to commit our code to github repository.

You can also follow this url, I am always taking help of this page:

URL:  https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

Initialize the local directory as a Git repository

 git init 


Add the files in your new local repository. This stages them for the first commit.

 git add First.java 


Commit the files that you've staged in your local repository.

 git commit -m "your message that describe your commit" 


In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

 git remote add origin https://github.com/asifaftab87/java-core.git 


Push the changes in your local repository to GitHub.

 git push origin master 


Once u run git push origin master terminal would ask your githubId/github registered email id  and password.

Once done then your code already committed to your github repository.

git remote add origin remote url

Above command used only when we are adding a file/folder/project to a very newly created repository, e.g. if repository is new and nothing inside repository then we have to use

git remote add origin remote url

else we skip this command.

So to commit file/folder/project in git which is already having other project or old repository then commands are

 git init 

 git add First.java 

 git commit -m "your message that describe your commit" 

 git push origin master 





No comments:

Post a Comment