DEV Community

Khafido Ilzam
Khafido Ilzam

Posted on

Working with Git

What does Git do?

  • Manage projects with Repositories
  • Clone a project to work on a local copy
  • Control and track changes with Staging and Committing
  • Branch and Merge to allow for work on different parts and versions of a project
  • Pull the latest version of the project to a local copy
  • Push local updates to the main project

Working with Git

  • Initialize Git on a folder, making it a Repository git init
  • Git now creates a hidden folder to keep track of changes in that folder .git
  • When a file is changed, added or deleted, it is considered modified
  • You select the modified files you want to Stage git add . , alternatively you can add specific files: git add file1 file2
  • The Staged files are Committed, which prompts Git to store a permanent snapshot of the files git commit -m "your commit message"
  • Git allows you to see the full history of every commit. You can revert back to any previous commit (will explain it later..)
  • Git does not store a separate copy of every file in every commit, but keeps track of changes made in each commit! git log

Now, your project is under version control with Git. You can continue to make changes, stage them, and commit them as needed. Additionally, you may want to connect your local repository to a remote repository on a platform like GitHub using commands like git remote add and git push.

The git remote add command is used to add a remote repository reference to your local Git repository. A remote repository is a version of your project hosted on another location, typically on a different server or platform (e.g., GitHub, GitLab, Bitbucket). Adding a remote allows you to interact with and push/pull changes to/from that remote repository (will explain it later..).

Remember that this is just a basic setup. As your project progresses, you may need to learn more advanced Git commands for branching, merging, pulling, and collaborating with others.

Top comments (0)