This page looks best with JavaScript enabled

Git in 5 minutes

 ·  ☕ 2 min read  ·  ✍️ Syed Dawood

Yes, you read it correctly.5 minutes.I will not be covering what is version control or what is git. Rather a basic workflow with git.

  • Init or clone

  • Add (for init)

  • Commit

  • Pull-Push

init or clone

Here it starts, you want you use git for existing project which was not in any version control. This is very first step.fire up terminal/command prompt.

1
git init .

or you can clone a repo(a fancy word for code in VCS) in this context. here's how you do it.

1
git clone https://github.com/allsyed/awesome-vim

Lets move to next step.

Add

So you've initialized repo in the current directory but your files are not being tracked because you haven't said git to do so.In git terminology we call it staging changes.if you've just cloned a repo, this step is not needed unless you've added new files are did some changes to existing ones.

git status run this command every now and then to see whats current status of your project.

1
git add [<FILE_NAME>|.]

This command will stage file(s) in the repository.

Commit

Wait, In last step we did added changes right?. Whats with committing? .Think of it this way,staging changes means you have prepared files to commit.Well people who are gamers can think of commit as a save point.Once saved, you know you can jump back to save point,if you break something.

1
git commit -m "Write your commit message here"

Protip: use git status often

You will see a verbose output about what git is doing,read through if this is your first time.

Pull-Push

Great you've committed , now what.Now lets push the changes to server.But hold your horses it a best practice to pull before you push.If you are only one who is making changes you don't have to worry about overwriting changes.Server can be anything [GitHub, Gitlab, bitbucket or any other]

1
git pull <remote_branch_name>

ex : git pull origin

Here some conflicts may occur like you have changed a file and other contributors have done the same. So, compare files include or exclude changes and commit. Now you are good to go. Lets push it

1
git push <remote_branch> <local_branch>

ex: git push origin master

conclusion

This is like 50-60% of git you will ever need to know.Jump in and use you it your next project. The infographic below will explain if you didn't catch my point.


digraph MyGraph {
  "init/clone" -> "add/change"
  "add/change" -> commit
  commit -> pull
  pull -> push
  push -> "add/change" [dir=both]
}
Share on
Support the author with

ALLSYED
WRITTEN BY
Syed Dawood
< frontend | backend | fullstack > Developer | Programmer