Getting Started with Git and pushing existing project on GitHub
At the heart of GitHub is an open source version control system (VCS) called Git. Git is responsible for everything GitHub-related that happens locally on your computer.
Setting up Git
Download and install the latest version of Git from here.
- To double check that Git is installed, Open Git Bash, type
- To configure Git, you must define some global variables:
user.email. Both are required for commits.
i) Setting Username :
git config --global user.name "<USER_NAME>"
ii) Setting Email :
git config --global user.email "<USER_EMAIL>"
Congrats! Now you have successfully setup Git in your computer.
Pushing your project on GitHub
- Now open your GitHub account. and create a new repository on GitHub.
To avoid errors, do not initialize the new repository with README, license, or .gitignore files. You can add these files after your project has been pushed to GitHub.
2. Open Git Bash on your Project Location.
3. Initialize the local directory as a Git repository.
$ git init
4. Add the files in your new local repository. This stages them for the first commit.
$ git add .
Don’t forget the period at the end of the command. It tells Git to index all of the files in the current directory that have been added or modified.
5. Commit the files that you’ve staged in your local repository.
$ git commit -m "first commit"
6. At the top of your GitHub repository’s Quick Setup page, click to copy the remote repository URL.
7. Paste this URL by right clicking onto Git Bash followed by the command.
$ git remote add origin <remote repository URL>
8. Push the changes in your local repository to GitHub.
$ git push -u origin master
For pushing forcefully
$ git push -f origin master
now refresh your GitHub repository. Congrats !!! You did it.
Hope you enjoyed pushing your first project on GitHub.
Thanks a lot for reading till end. You can contact me in case if you need any assistance: