14 Jan

Introduction to git commands – Your first git commit

Introduction to git commands - your first git commit
Here is a basic introduction to help you start using github and make your first commit to your github repository.
1. Initialise a git directory:

Create your project directory then browse to that directory via git shell or terminal and type the following command.

This command will initialize a git directory. You should see the message “Initialized empty Git repository”.

2. Add some files to your directory :
Now we will add some files to the project directory.

Here we have created two text files.

3. Check new files status and stage them for commit :
Now we need to see changes that we want to commit. Use the following command to see untracked files.

you will see a list of new files added and a message “nothing added to commit but untracked files present”
Now we need to stage these files for commit.

Now using add command we have staged all the files for commit. We have used dot(.) to specify all files. You can also use file or directory name if you want to be specific.

git status command will list all the files we just added for commit.

4. Commit changes :
Now we need to commit the changes we just made.

here -m is used to add a message to commit.

5. Create a git repository :
Login to your git account and create a git repostitory. You can also use existing one. In my case it is “testgit”.

6. Add remote origin of git repository :
Now we need to add origin of our repository.

here vineetgarg90 is my git username and testgit is my repository name. Replace these values with yours.

7. Push changes to remote git repository :
Now we will push all the changes to our repository.

here master is name of branch we are pushing changes to (this is default branch of every git repository).
You will be prompted to provide your git username and password. Once you enter them, all the changes will be pushed to your git repository.

7. Pull changes from remote git repository :
If you want to pull changes from remote repository that are not present in your local repository, use the following command.

now all changes will be pulled to local repository.

There are many more git commands but these should be enough to start with, try them yourself and  share your thoughts in comments. :)


The following two tabs change content below.

Vineet Garg

Sr. Web Developer at GuestHouser
I am passionate about technology and web development.

Latest posts by Vineet Garg (see all)