Quick setup new repository on the commands 💻

new image

You should know!

You should already have a good understanding of how this works from the previous chapters Git Vs GitHub. This chapter focuses on Git.


Quick setup

  1. git init
  2. git add .
  3. git commit -m "first commit"
  4. git branch -M main
  5. git remote add origin https://github.com/username/repositery.git
  6. git push origin main

Git init

The git init command creates a new Git repository

git init

Git add .

The git add command adds a change in the working directory to the staging area.

git add .

Git Commit

The git commit command captures a snapshot of the project's currently staged changes.

git Commit -m ""

Git branch -M main

A branch in Git is simply a lightweight movable pointer to [a commit]. The default branch name in Git is master. As you initially make commits, you're given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically

git branch -M main

Git remote add origin

git remote set-url origin "https://github.com/USERNAME/REPOSITORY.git". you can verify that the remote URL has changed

git remote add origin url

Git Push

Origin is simply the name given to any remote repository available on GitHub. Whenever we need to push the changes to a remote repository

git push origin master

Git Pull Origin

it downloads new changes from the branch named master on the remote named origin and integrates them into your local HEAD branch.

git pull origin master

Tip

commit messages are very important! Let everyone know what has changed and why. Messages and comments make it so much easier for yourself and other people to keep track of changes.

git Clone

git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location.

git clone url