Git is a version control system for recording changes to source code. It helps you review a project’s history, return to earlier work, develop features separately, and collaborate without passing around ZIP files or USB drives.
Why use version control?
When several copies of a project are shared manually, it can be hard to tell which files are current or who changed what. Team projects add more challenges: people may edit the same files, combine their work, or need to resolve conflicting changes. Git records changes as commits and provides tools for managing these situations.
Install and check Git
Download Git for your operating system from the Git SCM website. After installation, open a terminal and run git --version to check that it is available. You can work through Git commands in the command line or use a graphical interface if that is easier to learn.
Start a repository and save changes
git initcreates a repository in the current folder and adds a.gitdirectory for Git’s data.git addstages selected files so they can be included in the next commit.git commitrecords the staged changes with a message describing the work.git statusshows which files have changed and which are staged.
A commit gives you a named point in the project history. Clear commit messages make it easier to understand what changed and why.
Use branches to work in parallel
A branch lets you develop a feature, fix a bug, or test an idea without making those changes directly on the main line of work. The lesson introduces git branch for managing branches and git checkout for switching between them. When the work is ready, git merge combines changes from another branch into the current branch.
Work with remote repositories
A remote is a repository stored elsewhere, for example on GitHub, GitLab, or Bitbucket. Use git remote to view or manage remote connections, and git remote add to connect a local repository to a remote one. git clone copies a remote repository to your computer; git push sends local commits to a remote, and git pull brings remote changes into your local work.
Resolve merge conflicts
Git may not be able to combine changes automatically when two branches edit the same lines, or when one branch deletes a file that another changes. Review the conflicted file, decide which changes should remain, remove the conflict markers, and commit the resolved result. Check the outcome carefully before sharing it.
Explore the project history carefully
The lesson also covers tools for moving through or reshaping history: git checkout can switch to a branch or inspect an earlier commit; git reset can move the current branch reference and may change staged or working files depending on its options; git revert creates a new commit that reverses an earlier change; git cherry-pick applies a selected commit to the current branch; and git rebase changes the base of a branch. These commands can affect shared work, so understand the result before using them.
Squashing combines several commits into one, but Git does not provide a standalone built-in git squash command. Check the documented workflow for your Git client, and coordinate before rewriting commits that have already been shared with a team.
For a free financial consultation, contact the team on LINE. You can also scan the QR code to add the team on LINE.
