git in 5 minutes

Yes you read it correctly,5 minutes.I will not be covering what is version control or what is git . We will directly get our hands dirty

  1. Init or pull
  2. Add (for init)
  3. Commit
  4. Pull-Push

 

init or clone

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

$ git init

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

$ 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 coz you haven’t said git to do so.In git terminology we say 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.

$ git add .

This command will add all files 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.

$ 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, bitbucket or any other]

git pull <remote_repo_name>

ex : git pull origin

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

git push <remote_repo> <local_repo>

ex: git push origin master

Conclusion

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

git-infographic

 

Resources

 

git-scm (https://git-scm.com/documentation)

github (https://help.github.com/)

bitbucket (https://www.atlassian.com/git/tutorials/)

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

%d bloggers like this: