Before we get started, let’s answer the question “what is
The goal of the platform is to make collaboration easier for teams on large projects. Git increases speed, integrity, and workflow efficiency. Git is used by more than 1,700 companies around the world (through different git platforms such as GitHub and GitLab).
Now for the fun stuff; how do you use Git?
For the purpose of this post, I am introducing git on the command line. This is the most common way to interact with a git platform. Let’s jump into it!
Create a New Repository
Open a new directory and perform
Checkout a Repository
This will create a local copy of a git repository. Issue the following
git clone /path/to/repo
You may be asked to input your credentials to the git platform you are trying to access.
Add & Commit
When you have made changes to the source code and you are ready to propose these changes to the repository, you will need to add the file (or files) to the Index using
git add <filename> # OR git add *
You have now successfully added the files(s) to your index. In order to actually commit these changes, we run the following command which will include a comment or message about the
git commit -m "I made changes"
The files you made changes to have now been committed to the HEAD.
Push Changes to Remote Repository
Now that we have successfully committed our changes to the HEAD, we need to push our changes to the remote git platform. This is done through the
git push origin master
where master is the name of the branch we are pushing these changes to.
Get Changes from Remote Repository
If you are working in a repository with other people, you should always update your local repository to the newest commit so that you are certain you are working on the latest revision of the source code. Execute the following
Sometimes, you might have made local changes and need to override these changes with the latest code from the remote repository (important to note that this overrides and replaces all your local changes). This can be done by executing the following three (3) commands:
git checkout -- <filename> git fetch origin git reset --hard origin/master
Again, this will replace the selected files or repo’s local changes and restore it with the latest history from your git platform.
This concludes this simple little guidance. I am working on another guide that goes more in-depth into how you can manage a git repository from the command line. In the meantime, check out another simple little guide here.
Thank you for taking 10 minutes out of your day to trust me to teach you something new. Feel free to leave me a comment below with your concerns or feedback.