Interview Prep
Interview questions, roadmaps and practice sets
Tutorials
Free tutorials on 30+ topics
Blog
Career guides, skills and interview tips
Free PDFs
Notes, cheat sheets and question banks
Certificates
Free skill tests and course certificates
Tools & Whiteboard
Free tools you can use right in the browser
Practice Tests
Mock tests, MCQs and quick Q&A
Free LMS
Learn on the Uncodemy LMS
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →
Free tutorials, interview questions, tools and calculators to help you learn.
Explore →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →In Git, commit saves a snapshot of your staged changes in your local repository, push uploads your new commits to a remote such as GitHub, and pull downloads other people's commits and merges them into your branch. This guide shows each command with real output, then covers the two problems beginners hit most: a rejected push and a merge conflict.

Commit, push and pull only make sense once you know where Git keeps your work. There are three locations:
.git folder on your machine. It stores every commit you have made. It also has a staging area (the index), which holds the changes you have marked for the next commit.origin.Each command moves changes between these places:
| Command | Moves changes from | To | Needs network? |
|---|---|---|---|
git add | Working directory | Staging area | No |
git commit | Staging area | Local repository | No |
git push | Local repository | Remote repository | Yes |
git pull | Remote repository | Local repository and working directory | Yes |
If you want the bigger picture of why teams use version control at all, read what version control is and why it is used first.
A commit is a snapshot of the staged files plus some metadata: author, date, a message and a pointer to the previous commit (its parent). Git identifies each commit by a SHA-1 hash; you normally see the first seven characters.
Committing is a two-step process. First you stage what you want, then you commit it:
$ git status --short
M index.html
?? contact.js
$ git add index.html contact.js
$ git commit -m "Add contact form validation"
[main 3f2a1c9] Add contact form validation
2 files changed, 41 insertions(+), 3 deletions(-)
create mode 100644 contact.js
In the git status --short output, M means a tracked file was modified and ?? means a new, untracked file. Your hash and line counts will be different from the ones shown here.
Points that trip people up:
git commit -a -m "..." stages modified tracked files automatically, but it does not add new untracked files such as contact.js above.git log and code review far easier.git push sends the commits your remote branch does not have yet, then moves the remote branch pointer forward.
$ git push origin main
...
To github.com:your-user/demo-site.git
9b1e2d4..3f2a1c9 main -> main
The line 9b1e2d4..3f2a1c9 main -> main means the remote main moved from commit 9b1e2d4 to your commit 3f2a1c9.
The first time you push a new branch, add -u (short for --set-upstream). Git then remembers which remote branch it tracks, so later you can type plain git push and git pull:
$ git switch -c feature/contact-form
$ git push -u origin feature/contact-form
Pushing to GitHub needs authentication. GitHub stopped accepting account passwords for Git operations over HTTPS in 2021, so use an SSH key or a personal access token. GitHub's own documentation walks through both.
If a teammate pushed to main after your last pull, the remote has commits you do not. Git refuses to overwrite them:
$ git push origin main
To github.com:your-user/demo-site.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'github.com:your-user/demo-site.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. ...
The fix is to pull first, then push again. Do not reach for git push --force on a shared branch: it replaces the remote history with yours and deletes your teammate's commits from the branch.
git pull is two commands in one:
git fetch downloads new commits from the remote and updates origin/main, your local record of where the remote branch is.origin/main into your current branch, by a merge (the default) or a rebase if you ask for one.If you have no local commits of your own, the pull is a simple fast-forward: your branch pointer just moves ahead. If both sides have new commits, the branches have diverged. Recent Git versions then ask you to choose a strategy once:
# keep a merge commit when branches diverge (the classic behaviour)
git config --global pull.rebase false
# or replay your local commits on top of the remote ones (linear history)
git config --global pull.rebase true
Both are valid. Many teams prefer rebase for a tidy history. A merge is easier to undo while you are learning. If you only want to look at incoming changes before integrating them, run git fetch and then git log main..origin/main.
A conflict happens when you and a teammate changed the same lines of the same file. Git stops the pull and marks the file:
$ git pull origin main
Auto-merging config.js
CONFLICT (content): Merge conflict in config.js
Automatic merge failed; fix conflicts and then commit the result.
Open config.js and you will see both versions between markers:
<<<<<<< HEAD
const MAX_NAME_LENGTH = 50;
=======
const MAX_NAME_LENGTH = 80;
>>>>>>> 4c7d1e0...
The part above ======= is yours (HEAD). The part below is the incoming change, labelled with the commit it came from. Edit the file so it contains the code you actually want and delete all three marker lines. Then finish the merge:
$ git add config.js
$ git commit # Git pre-fills a "Merge branch 'main' of ..." message
$ git push origin main
If you get lost halfway, git merge --abort puts everything back the way it was before the pull.
Here is the loop most developers repeat many times a day on a feature branch:
git switch main
git pull # start from the latest code
git switch -c fix/signup-crash # one branch per task
# ...edit files...
git status # see what changed
git diff # review the exact lines
git add src/signup.js
git commit -m "Fix crash when signup email is empty"
git push -u origin fix/signup-crash
# open a pull request on GitHub, get it reviewed, merge it
Working on a branch and merging through a pull request keeps main stable and gives teammates a chance to review your change. For a longer walk-through of branches and pull requests, see how to use Git and GitHub in a real project.
| Situation | Command | Safe after pushing? |
|---|---|---|
| Staged a file by mistake | git restore --staged file.js | Not relevant (nothing committed) |
| Typo in the last commit message, or forgot a file | git commit --amend | No: it rewrites the commit |
| Undo the last commit but keep the changes | git reset --soft HEAD~1 | No: it rewrites history |
| Undo a commit that is already on the remote | git revert <hash> | Yes: it adds a new commit that reverses the old one |
The rule of thumb: rewrite history only for commits you have not pushed. For anything already shared, use git revert.
README.md, commit it and push it.Doing this once makes the whole cycle concrete. After that, try a small project from these GitHub practice projects for full stack learners. If you are new to Git itself, what Git is and how to install and use it covers setup, and version control explained for full stack learners shows where Git fits in a web project.
git commit saves a snapshot of your staged changes in your local repository only. git push uploads those local commits to a remote repository such as GitHub so other people can see them.
git fetch only downloads new commits and updates remote-tracking branches like origin/main; it does not touch your files. git pull runs a fetch and then merges or rebases those commits into your current branch.
If the remote branch has commits you do not have, Git rejects your push. Pulling first brings those commits in and lets you resolve any conflicts locally before you push.
Yes. Use git revert with the commit hash. It creates a new commit that reverses the change, so the shared history is not rewritten and teammates are not affected.
Git, GitHub and branch-based teamwork are covered hands-on in Uncodemy's full stack developer course.