Git is a tool that keeps track of changes to files, lets you work together with others, and saves a history of your project. This guide explains the basics you need to start using Git, especially how to work with branches.
Stage changes – tell Git which files to include in the next snapshot:
git add <file># or add everythinggit add .
Commit – record a snapshot with a message:
git commit -m "Add a clear, short description"
View history – see past commits:
git log --oneline --graph --decorate
Push – send your commits to the remote repository:
git push origin <branch>
For a new branch you must use:
git push --set-upstream origin <branch>
Pull – fetch and integrate changes from the remote:
git pull --rebase
This updates your local branch with the latest changes.
Handle conflicts – if a conflict occurs during merge or pull, Git will mark the conflicting files. Edit the files to resolve the conflicts, then stage the resolved files and continue:
# after editing conflicted filesgit add <resolved-file>git commit # or git rebase --continue
Rebasing rewrites the commits so they appear as if they were created directly on top of the latest main branch. Only rebase branches that no one else is using.