World’s simplest Git tutorial for quick reference

Git Workflow (Image courtesy WSO2 Team)
  1. Fork the repository that you want to work with by visiting the Git repository and clicking the “Fork” button in the top right-hand corner. We’ll be using the below repository as the example in this tutorial.

https://github.com/chanakaudaya/solution-architecture-patterns

It will take a moment to fork the repository to your GitHub account or organization that you select when forking…

2. Click on the “Code” button and copy the clone URL

3. Install the “Git” CLI tool in your workstation (laptop, desktop, VM) if you have not installed it yet.

4. Clone the forked repository by executing the below command

git clone git@github.com:<username>/solution-architecture-patterns.git

5. Point the pull URL to the original repo

git remote set-url origin git@github.com:chanakaudaya/solution-architecture-patterns.git

6. Point the push URL to the forked repo {note the (minus)(minus)push in the command}

git remote set-url — push origin git@github.com:<username>/solution-architecture-patterns.git

7. Check whether you have configured the repositories correctly by executing the below command

git remote show origin

You should see something like below as the response.

* remote origin
Fetch URL: git@github.com:chanakaudaya/solution-architecture-patterns.git
Push URL: git@github.com:<username>/solution-architecture-patterns.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for ‘git pull’:
master merges with remote master
Local ref configured for ‘git push’:
master pushes to master (fast-forwardable)

8. Now you are all set to work on the project. Make some changes to existing files and commit those changes with the below command.

git commit -m “commit message”

9. Update your changes to the remote repository forked into your account with the below commands

git pull (pull the changes from the original repository)

git push (push the local changes to the remote forked repository)

10. Go to the forked repository and send a PR (Pull Request) to the original repository from GitHub.

Advanced Steps

If you prefer using “branches” for creating new features, you can follow the instructions mentioned below after the #7 point above.

11. Create a branch from the master branch for each feature that you work on

git checkout -b feature1 master

12. Make sure you are in the created branch by executing the below command

git branch

You should see the branch name in the output to the above command

13. Do the changes (development) and commit the files to the newly created branch by executing the below command

git commit -m “commit message”

14. Once you commit the changes to the new branch, switch back to the master branch with the below command

git checkout master

15. Update the master branch with any changes that happened at the original repository with the following commands

git pull

git push

16. Switch back to the feature1 branch with the below command

git checkout feature1

17. Now rebase the master branch so that you save the commit history from the master branch and append your work to the same history with the below command

git rebase master

18. If there are any conflicts, you can resolve those conflicts and once you are done with the resolution, push the changes to the remote (forked) repository with the below command

git push origin feature1

19. Now you can go to the repository and send a PR (Pull Request) from “feature1” branch to “master” branch of the original repository

That’s all!!!

Engineer | Author | Speaker | Associate Director @ WSO2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store