Technology

Git Commands – The Basics

working

Have you started working on git recently and feel a little clumsy about its command line way? I have been there too, and being a UI friendly guy, I even sometimes forget its commands anyway.

So here are some basic commands to get started. This also works as my come-back-point, whenever I get lost 😉

 

Get Started With a New Project:
All steps at a glance
Create a new project in git. And then do,
git clone {project-git-url}.git
Explanation

1: Open your git site (Github, Gitlab, etc).

2: Create a new project and write down the git path.

Something like www.{git-site}.com/{your-user-name}/{your-project-name}.git – Will be referred as {project-git-url}.git from now on.

3: Go to your drive/workspace via the command line interface. Then do a

git clone {project-git-url}.git

4: Viola! The project is now in your local system to start working on. Now get-set-go. 🙂

Pushing changes to git:
All steps at a glance
git add .
git commit -m "your message"
git push origin master

 

Explanation

1: Open your project folder via the command line
2: Add all the files to commit via

git add .

3: Then commit the changes with a message by

git commit -m "your message"

4: Then push the changes to git server by

git push origin master

 

Pulling changes from git:
All steps at a glance
git pull

Simple. Isn’t it?

Explanation

1: Open your project folder via the command line

2: Do

git pull

This will ask for authentication if your credentials haven’t already been saved. Do the authentication, and you now have the latest changes from the server to work with. Make sure to do a git pull before starting with changes in your local code.

 

Downloading an existing project (Can be yours or anyone else’s):
All steps at a glance
git clone {project-git-url}.git
Explanation

1: Find the {project-git-url}.git

2: In your drive, do a

git clone {project-git-url}.git

Same to the previous one, isn’t it? Of course it is. That’s the simplicity of git. 🙂

 

Uploading an existing project to git:
All steps at a glance
git init
git remote add origin {project-git-url}.git
git add .
git commit -m "your message"
git push origin master
 Explanation

1: Create the git url as specified in the “Get Started With a New Project

2: Navigate to your project folder via the command line utility.

3: Once inside, type

git init

This will make your project folder ready to be worked with git. You should see a .git folder inside your project now. This is a hidden folder, so you should only see it, if you have turned on to see hidden files and folders.

4: Then type,

git remote add origin {project-git-url}.git

5: Then type,

git add .

6: Then,

git commit -m "your message"

7: And finally,

git push origin master

 

Murari Mohan Nayak (Murari M.)

Leave a Reply

Your email address will not be published. Required fields are marked *