DEV Community

Irwan Phan
Irwan Phan

Posted on

Getting Started With Git? A Complete Git Beginner.

I try to recall my first time using git. I was not a tech-guy back then, not even close. Pencil, Pen, and Photoshop was my daily tools back then.

Later I jumped into web development. When my peer told me about collaboration using git, it overwhelmed me with command-line-stuff. I thought it was a really complicated stuff. But my peer just gave me some simple commands for daily use. And I only use those some-simple lines until now, except sometimes-unexpected things happened.

I am writing these down, since I had to share how to use git to my class. And I just gonna skip the complicated parts. Hope it helps

Install Git, If It's Not Installed Yet

Site to Download Git

Download the installer from https://git-scm.com/download/win, ran the installer, and if you don't understand anything the provided options presented, just go with the default.

Using Git

Terminal in VSCode

Git commands can be directly used from VSCode terminal, you can open the terminal by pressing Ctrl + Shift + `. Or you can open it from the top menu Terminal, then choose New Terminal.

If It Is An Existing Repository

1. Clone The Repo

Github Repository

If-it is an existing Repository, go to the repository on Github, click the "Code" button, and copy the git url (you can just click the right side button). then go back to the terminal and type git clone command like this. (using the developer-roadmap repo as example)


git clone https://github.com/kamranahmedse/developer-roadmap.git

2. Config - One time only

This command actually write the config file inside the hidden .git folder. We'll skip it, just remember that you can always re-config using this command.


git config user.email "tapas@someemail.com"
git config user.name "Irwan Phan"

3. Add and Commit Changes

To add the files changed to staging, we use the git add command follow by file name or directory/folder name. But we can also just add all the changed files by using . like below.


git add .

The next thing to do after added the changes to staging area is to commit it using git commit command, and remember to always makes the commit title as clear as possible.


git commit -m "change the x part with x2y"

4. Push To Repo (Remote Repository)

Push the committed changes to the remote repo by using git push command follow by remote and branch name, e.g main. If it's a cloned repository, you'll only need to type git push.


git push

If It Is A New Repository

1. Initiate A Repo

To create a new repository, we can use the git init command followed by repository name, or just git init.


git init repo-name

2. Config

Use git config for user name and email used in your Github like mentioned in step #2 above.


git config user.email "tapas@someemail.com"
git config user.name "Irwan Phan"

3. Add And Commit Changes

Use git add to add to staging and git commit to commit the changes.


git add .
git commit -m "change the x part with x2y"

4. Push To Repo (Remote Repository)

To push to a new remote repository use git push_ command followed by __-u, remote, and branch name.


git push -u remote main

Wrapped

I hope this note could be of help for anyone. I tried to make it as simple as possible. For more information on how to use git, you can visit here https://training.github.com/downloads/github-git-cheat-sheet/.

Top comments (0)