DEV Community

loading...

Gitty Gitty Up!

kerocare profile image Care ・4 min read

In the world of coding, while information is easily accessible, it's also rather overwhelming. A good place to start is Git, one of the most popular free and open source version control systems. This being helpful when working in any number that is more than one, or just helpful in keeping track for larger projects.

As a beginner in this, let's walk through this together!

Beyond simply knowing how to do, but understanding how Git allows users to "commit" in order to create a smoother and more coherent team experience (not just for coding) regarding data integrity, flexibility, and consistency. That is what the end goal of our little learning journey is.

Beginning with, it is necessary to install Git itself and then try out different methods and UIs (user interfaces) you may prefer. For now, I'm choosing only to do the basics with the GitHub website (not inherently tied together with Git as many may assume but widely used) and simple command line. Here's my Video on it and the transcribed steps with it:

1. First off, Install Git

I simply used the Git website to get started:
Download Git Here

You won't need this for committing via the GitHub browser but if you want to make commits via the command line or terminals, then you'll need it!

2. Learning Terminology

At first I was confused because git seemed like something way out of my pay grade (of $0), but it's like every other new language. Everyone has to start somewhere so here are so of the most common vocab:

Repository - container or project for Git, shortened to "repo" at times
Local - on your own local, personal device
Remote - the one shared on some server usually with teammates to keep track of files and changes
Commit - mark a time in your code
Pull - pull current code or "download" from source code
Push - push or "upload" code to source code base (others will be able to see what changes you have made)
Fork - making a copy of repo ("fork it over")
Clone - make a separate copy or clone of the source code that is
Branch - branch off of the tree or separate timeline off the source code
Tag - mark a time in your repo

Thankfully Git itself has helpful guides to those simply starting off. You're always a search away from answers (usually).

3. Creating a Remote Repository and Initializing a Local Repository

It is possible to make a local repository but most software developers collaborating do so via a remote repository so we will focus on that. To do that, we will be utilizing GitHub, which is often paired together with Git as it is reliant on it.

On GitHub:
a. Start by creating a GitHub account or logging into an already existing one
b. Click "Start a Project"
c. Enter the name you wish to give your repository, toggle any desired features on and off
d. Create repository

Now you should have a pretty empty repository that we are going to start populating with files via your local device next.

On the Command Line:
By inputting this into your command line terminal interface, it should initialize your local repository:

git init

4. Add Local Files to Local Repo

Create a file or add an existing.
git add . to add all files in your project but if you only want to add a specific file then do
git add FILENAME

5. Committing via Different UIs

a. GitHub (requires an account)
GitHub actually offers the ability to manually commit and make a push or pull request on its own site.

b. Command Line
While it may seem a lot, memorizing these few commands can help you in the long run by a lot. These should work whether via a IDE's command line or your device's terminal itself.
git commit -m "message here i.e. new file added"

6. Connect Remote and Local Repositories

Input: git remote add origin URL
with the URL part instead being the URL of your GitHub repository.

7. Create Main Branch and Timeline

Usually when a main branch already exists, creating a separating branch or timeline is a good call for possible conflicting changes. However for now, since we were just going through the basics, I simply did;
`branch -M main"

8. Push Commits to Remote Repository

git push -u origin main

I definitely feel like commits via the command line might be more neat in the long run (keeping track with different users) though it has a slightly higher learning curve than using just the GitHub browser. The GitHub browser method of committing is overall easy for daily activities involving Git though.

Other Tips
For committing via the command line, friendly users of git have told me spamming a few of these commands is really helpful if you have anxiety on accidentally rattling the main tree. They're also just neat ways to keep check and log of all updates to the project in comparison to your branch.

Other helpful commands:
git branch - checks what branch you're on
git branch <name> - creates another branch
git log - shows a log of all commits you have made
git status - tells you your remote repository and untracked files compared to the main remote repository's status and changes

Video on This: https://www.youtube.com/watch?v=j-sQuJtnKaU
YouTube Channel: https://www.youtube.com/channel/UCjR8IqMXgs6H69ZQqrsS1Vw

Discussion (0)

Forem Open with the Forem app