What’s it all about?
Git is an open-source revision control management system, a very efficient tool for managing projects of all sizes. While I won’t delve into the specifics, I encourage you to visit the official site at git-scm.com for comprehensive information on all the intricacies and details you seek.
Where to store your repositories
There are many places to keep track of and hold your repositories, here are two out of many possibilities;
GitHub is the perfect app to assist with project collaboration. It allows you to commit changes, send pull requests and manage all your public and private git repositories.
Bitbucket, provided by Atlassian, offers you unlimited private repositories, with up to 5 users.
Let’s make a start
For a basic list of commands.
When you first set up Git, you’ll need to set your username and email address to ensure changes (commits) are recorded properly.
git config --global user.name "your name" git config --global user.email "firstname.lastname@example.org"
Creating a new repository
git clone username_@host/path/to/your/repository
git clone /path/to/your/repository
This is useful for creating a local copy of a remote repository and allows you to start working on the project, make changes, and collaborate with others.
Check your repository status
This provides an overview of the current state of your repository, shows which files have been modified, added, or deleted, and helps track changes and determine the next steps in your workflow.
git add filename.php
You can add a specific file or directory to the staging area, it prepares the file for the next commit. It’s also useful when you want to selectively stage changes instead of committing everything at once.
git commit -m "commit message"
Commits act as milestones in your project’s history and are useful for tracking progress, rolling back changes, and collaborating with others. Adding a descriptive commit message helps you and your collaborators know what was changed.
This command sends your committed changes to a remote repository, typically on a hosting platform like GitHub. Useful for sharing your work with others or deploying updates to a production environment.
This retrieves the latest changes from a remote repository and merges them into your local branch. Useful for keeping your local copy up to date with the latest code changes made by collaborators.
This will list all branches within your repository and show your current branch, it also helps you visualise the branching structure of your project.
git checkout [branch_name]
Checkout will switch to a different branch in your repository. This is useful for creating new features, fixing bugs, or working on separate tasks without affecting the main branch.
git merge [branch_name]
This combines changes from one branch into another branch and is useful when you want to integrate new features or bug fixes into the main branch of your project.
Git log displays the commit history of your repository and shows who made changes, when they were made, and the commit messages associated with each change. This is helpful for understanding the project’s development timeline and reviewing past changes.
These Git snippets are useful for everyday version control tasks, enabling efficient collaboration, tracking changes, and managing project history. Mastering these commands will enhance your productivity and help you leverage the power of Git for effective source code management.
Feel free to adapt them to your specific repository and workflow needs.