Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 16, 2021 10:30 am GMT

Step By Step Guide To Push Your First Project On GitHub

Depending on your situation, or what you are trying to do, there are probably a dozen ways to push your source code for for the first time to GitHub. But Im these six git commands are the only ones I use.
My situation is a little simpler. I use GitHub just for my personal work. I dont really collaborate with anyone. I dont use branches. I work on the master directly. I use Windows. If this is your situation as well, then this post might help you.

Set Up Your Environment

I assume that you have already set up your environment to use the git commands. If not, make sure you do the following first:

  • Install Git SCM on your computer to enable you to use git on the command line.
  • Register at GitHub. Then, create an empty repository.

The Six Commands

I run these six commands in this order:

git init
git add -A
git commit -m your message
git remote add origin https://github.com/username/reponame.git
git pull rebase
git push -f origin master

git init

Initializes and prepares your directory for git. Suffice it to say that you need to open a command prompt or PowerShell CD to your source code directory type git init and Enter. You can execute git status at any point in time to see where youre at in the process.

git add -A

Prepares all changes on staging. The -A means all changes are staged including edits, additions, and deletes. I do this because I dont have to think!

git commit -m

Commits all the changes. After commit, you are ready to push to GitHub.

git remote add origin

Associates your directory with a remote git server and repo. The URL of your repo is that URL that you see when you click the Clone or download button. You can execute git remote -v to verify that your directory has been associated with your remote repo.

git pull rebase

This step is somewhat controversial. I only use this because I am pushing directly to a master, so I need to pull from the remote first before pushing. In fact, if I dont use this, it wont let me push! According to Atlassian, its like saying, I want to put my changes on top of what everybody else has done. So, this is perfectly fine for my situation.

git push -f origin master

Because I did a pull rebase, I need to force or use the -f directive.

Thats it

Let me know what you think!


Original Link: https://dev.to/codehunterbd/step-by-step-guide-to-push-your-first-project-on-github-3aag

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To