Google Cloud

How Git Works – 7 Basic Steps for Beginners

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

Git is a distributed version control system created by Linus Torvalds in 2005. It also has an excellent support for branching, merging, rewriting repository history and more. Git is considered to be the modern standard for software development.

In this guide you are going to learn the basics of git workflows like

  1. Create a repository (project).
  2. Clone (copy) your repository to your local machine
  3. Add a file to your local repository and commit (save) the changes.
  4. Push the changes to your main branch.
  5. Create a branch (version), make commit, push changes to the new branch.
  6. Open a pull request (propose changes to master).
  7. Merge your branch to master branch.


Install Git on your system or server. Learn how to install Git on Ubuntu.

Step 1: Create new Repository

To create a new repository go to your development platform like GitHub or BitBucket or GitLab and follow the guide to create new repository.

Here is guide on how to create a new repository in GitHub.

Create new repository

Initialize Git

Now you need to configure Git with your name and email so that Git associates your identity with every changes you make.

git config --global "Your Name"
git config --global "[email protected]"

Step 2: Clone your repository

Create a new folder in your local system and navigate to your project folder and you can clone the repository that you created in the previous step.

Copy the SSH url from your repository.

clone repo

Now you can use the clone command to pull the repository.

git clone ssh_url .

You need to specify the “.” at the end of the command so that the files will be cloned directly into the local folder.

Step 3: Add new File and Commit

As you have the repository cloned to your local system, it is time to start the development process.

Now you can create a new file using the touch command.

touch filename.txt

This command will create a new file with the provided name inside your current directory.

Now you can check the status of your repository using the git status command.

Git Status

You will see something similar to the above screenshot which indicates the new file that is created is not tracked.

Now you can use the add command to tell git to track the file.

git add filename.txt

Now if you check the status again you will see the new file added.

Git add

Now use the commit command to save the changes.

git commit -m "Initial Commit"

You will receive an output similar to the one below.

Git commit

Step 4: Push changes to branch

Now you can push your changes to your remote repository using the push command.

git push -u origin branch_name
Git push

Now if you take a look at your project in GitHub or BitBucket you will see the new file gets added.

Step 5: Create new branch

Create the branch on your local machine and switch in this branch:

git checkout -b new_branch_name

Now you need to push the changes to remote.

git push origin new_branch_name

Step 6: Create Pull Request

Go to GitHub repository, you will see a notification to perform a pull request or you can go to the Pull Request tab and initiate a New Pull Request

 Pull request

Once the pull request is created you can accept and merge it or you can revise the code.

Step 7: Merge Branch

Now you can accept and merge your branch with the main branch.


Delete a Branch

To delete a branch you can delete the branch in local and apply the changes to the remote.

git branch -d branch_name
git push origin :branch_name


Now you have learned how to perform basic operations in git like create repo, clone, new branch, pull request, delete branch. etc

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.