GIT for new Software developers

GIT for new Software developers

Git commands you will need to get by as a starting-out developer.

image.png

Git? What exactly is git?

Git is a free and open-source version control system. More like your time travel machine, so when you make mistakes you can go to previous versions of yourself to tell them not to make the same mistakes. Only that this time it is your lines of code. If committed you can go back to previous versions of the code.

So let us get started. Check out some git terms and also for a more extensive read.
P.S: I assume you have basic experience in using the terminal.

Step 1. You install git on your computer.

You can do that by downloading git from Git site and installing it by running the executable file or for Linux Ubuntu users. $ sudo snap install git-ubuntu --classic

Step 2. Create a new git repository
This is done by initializing git on your computer. After navigating to the directory you are working on, input the following command in your terminal.

git init

This initializes git in that directory. Like that, git is now aware of the folder/directory and then begins to monitor the files added, removed, or changed in that directory.

Step 3. Add or stage your files

This is done by using the command

git add <NameofFile>

to stage a single file or

git add .

to stage all the files in that directory.

Step 4. Check to see if the staging is successful

This can be done by using the command

git status

This command is used to monitor the status of your git repository. Whether or not your commits were successful, or the staging successful. You can also use this to check the general status of your git repository.

Step 5. Commit your staged changes

This can be done using the command

git commit -m "Your preferred Message"

Step 6. Adding a remote repository

Several platforms host remote git repositories. Amongst which are Github, Bitbucket , GitLab . To mention but a few. These are git repositories that are on another server somewhere safe to enable you backup/host your code in the cloud. This also helps and supports team collaboration, enabling you to work with a team without having to work on one computer regardless of the location of each team member. One way you can do this is either you

  • Clone an existing repository with the command
git clone <HTTPUrlofRepository.git>

or you

  • add one to your repository and that can be done by using the command
git remote add <HTTPUrlofRepository.git>

Step 7. Push to origin

Run this command in the terminal

 git push --set-upstream origin <branchName>

a much shorter way of achieving this is by using

git push -u origin <branchName>

By doing this you are affirming that you want to move your code to a remote repository.

You can also change branches by using

git checkout <branchName>

or check for existing branches by using the command

git branch

and to add branches by using the command

git branch <branchName>

With these, you should have enough knowledge of git to go by as a starting-out software developer. I encourage you to learn more from online resources. I will recommend Git cheat sheet