This is an exciting journey to the world of Version control. Hoping you already opened a GitHub account?
Git is a widely used distributed version control.
Version control systems are a category of software tools that allows you to track changes to your code over time.
What's the difference between Git and GitHub?
Git is a widely used distributed version control while GitHub is a web-based hosting service that lets you manage Git repositories.
There are many other web hosting platforms that include: GitLab, Bitbucket, OneDev, Gogs, AWS CodeCommit, e.t.c.
Now that we know the difference between the two now lets install git.
Installation of git
Go to Git-Download
On the Downloads select the operating system you are using.
Select click for download or you can install via command prompt.
Once it's installed, on the terminal/using Git Bash(You'll see it on the start menu comes with installation of Git). Identify your identity. Use the commands below. replace the username with your GitHub username and email address
$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com
You can also configure your default branch to be main or just leave it as master
git config --global init.defaultBranch main
Confirm if you set the username right by typing
git config user.name
If you want to set the whole thing from the GUI(Graphic User Interface) then from your Start menu select GIT GUI
it opens up to this window.
You can choose to create a new repository then choose a folder you want your data to be in.
On the edit menu, select option
From this you can be able to still setup the configurations
Working with Git GUI
This will be the main working window from the GUI.
Window 1: Will show the unstaged files. These are files with no commit made. So unless they are staged they wont be pushed to GitHub.
Once you upload the files you intend to use in your current folder, you'll be able to see then in this window. If they do not reflect click on the Rescan
button.
Window 2: Is diff view, which shows the changes for the currently-selected file.
When you select a file, for example in our case we have the README.md
you can edit it in your text editor by clicking on the file(it appears at the top of the window when you select a file).
Window 3: Shows the files that are now ready for committing and pushing to GitHub.
For one to be able to send a commit message ensure at least one file is on this window.
Once you highlight the file from Window 1 then click the button stage changes
.
NB: You can toggle files between Window 1 and Window 3.
Window 4: Is the message and action area.Here you can write your commit messages.
If you want your local changes now to be in GitHub you need to create a remote.
Create a repository in your GitHub. Once you click the +(plus sign) follow the prompts.
Once on the Git GUI click on remote then add
Click on the code(green button) drop-down. For now we use. https. copy the link and add it to the GitHub remote location. You can name it origin(not a must) but most commonly used.
Our file is ready as we have already committed.
Then click on the Push
button.
Once you click push follow the prompts.
Using GitHub Desktop
Download GitHub desktop
Once installed an have connected with your GitHub account.
Click on create a new repository or clone repository(if repository already exists). Give the name and a bit of description.
That's the interface you get after creating. Click on publish repository.
The show in Explorer
button allows to open a text editor.
Edit your files in your editor of choice examples: notepad, VS Code. Once you've made the changes click on commit to main.
Click on push origin
button
Using GitHub Web
Once you have created your repository, click on the (+) plus sign.
From there one can upload files or create new files.
Once you click on the commit changes it will appear on your list.
It is an easy process similar to GitHub desktop
Using Command Line.
This can be on VS Code terminal, PowerShell, Git Bash or any terminal.
Confirm Git is installed.
git --version
I am currently using PowerShell and my version is 2.43.0
2. If a repository already exists and you want to clone it to your local machine. using the git clone
command
One can use the SSH or HTTPS. For now we use HTTPS
If the repository doesn't exist and we want to create a repository from our folder.
Open the terminal in the directory you’d like to convert
git init
This command initializes an empty repository.
Add the path to your remote repository.(copy as done above in clone process)
git remote add origin https://github.com/EstherNjuguna/dataanalytics.git
Create a branch
a branch is a copy of the files in the repository at the time you create the branch. You can create as many branches as needed. The default is main.
git branch -M main
The
-M
flag is used for branch renamingAdd and commit local changes
git add
is used. If you want to stage everythinggit add .
is used.git add <name of file or folder>
Confirm the files have been staged using
git status
Commit the staged changes
git commit -m "Your commit message"
Finally push the code to GitHub.
git push -u origin main
After the first push one can use
git push
.
Conclusion
We have learned 3 different ways of using git with GitHub as our web hosting platform.
You can choose to use the Command Line or GitHub desktop or GitHub on the web or even using Git GUI.
Whichever method is easiest to understand you can use that method.
Feel free to interact with the other learning resources attached here and also free to post any questions.