Skip to main content
LIVE CONTEST: Round #7 · Begin Marathon is live now! …

~/algor $ cat blog/git-va-github-boshlovchilar-uchun

Git and GitHub for Beginners: Essential Commands and a Daily Workflow

What is Git and how is it different from GitHub? A hands-on guide to installation, init, add, commit, branches, merge, push and pull, .gitignore and good commit messages.

Guides Views: 4
@iqbolshoh
Git and GitHub for Beginners: Essential Commands and a Daily Workflow — cover image
What is Git and how is it different from GitHub? A hands-on guide to installation, init, add, commit, branches, merge, push and pull, .gitignore and good commit messages.

Did your solution work yesterday, and today you "improved" it into a broken mess?

The professional answer is a version control system, and the most popular one is Git. It remembers every saved state of your project and lets you go back to any of them at any time. Below is the path from installation to pushing your code to GitHub.


1. Git and GitHub: what is the difference?

  • Git is a program on your computer. It tracks changes in your files and records them in the history as commits (saved "snapshots" of the project). It works fully offline.
  • GitHub is a service that hosts Git repositories online. You use it to back up your code, work in a team and build a portfolio.

2. Installation and first-time setup

On Linux sudo apt install git is enough, on macOS xcode-select --install, and on Windows the Git for Windows installer from the official website. Then configure Git once in the terminal:

git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

Your name and email are written into every commit, so use the same email as in your GitHub account.


3. Your first repository: init, add, commit

mkdir algor-yechimlar
cd algor-yechimlar
git init                  # turn the folder into a repository
echo 'print(sum(map(int, input().split())))' > a-plus-b.py
git status                # what has changed?
git add a-plus-b.py       # put the file into the staging area
git commit -m "Add a solution to the A+B problem"
git log --oneline         # commit history

In Git a file goes through three stages: the working directory → git add → the staging area → git commit → the history. git add . adds every changed file, and git diff shows what has changed before you commit.


4. .gitignore: leaving out unwanted files

Build output and editor settings should not end up in the repository. Create a .gitignore file in the project root:

a.out
*.exe
__pycache__/
.vscode/

Never commit passwords, tokens or .env files: a secret that reaches the history stays there even if you delete it in the next commit.


5. Branches and merging

A branch is a separate playground for experiments. You can try a new idea without breaking main:

git switch -c binary-search   # create a new branch and switch to it
git add binary.cpp
git commit -m "Add a binary search solution"
git switch main
git merge binary-search       # bring the changes into main
git branch -d binary-search   # delete the branch you no longer need

If the same line was changed differently in two branches, you get a merge conflict. Git puts the markers <<<<<<<, =======, >>>>>>> into the file: keep the correct version, delete the markers, then run git add and git commit.


6. Connecting to GitHub: remote, push, pull

Create an empty repository on GitHub and connect its address:

git remote add origin https://github.com/USERNAME/algor-yechimlar.git
git branch -M main
git push -u origin main   # the first time: with -u
git push                  # every time after that
git pull                  # fetch changes from the server

On another computer you download the project with git clone <address>. When you push, GitHub does not accept your plain password: you need a personal access token or an SSH key.


7. A good commit message

Bad Good
fix Fix out-of-bounds access in binary search
update Use priority_queue in the Dijkstra solution

The rules are simple: a short first line (roughly up to 50 characters) that says what was done, and one commit per logical change.


8. A typical daily workflow

  1. git pull to get the latest state.
  2. Write and test your code.
  3. git status and git diff to review your changes.
  4. git add + git commit with a meaningful message.
  5. git push to send it to GitHub.

Conclusion

Git is a programmer's everyday tool, and your GitHub profile is your public portfolio. For practice, create an algor-yechimlar repository and commit every solution to the ALGOR problems you solve: in a few months it will be the best proof of your progress!

Was it useful? Share it with friends:
Telegram

Related articles

All articles →