It took me to set up my Git and GitHub to realize how technology is sometimes not that straight forward at least for beginners. I mean setting up an account should be the easiest part of technology right? However Git and GitHub are packaged differently, forcing us to bear the brunt of its's convolution.
I'll break down the process to make it ingestible without intimidating a soul, because this too shall pass. Later, we will look back and be astonished of how something simple got our necks on a chokehold.
1. Installation
First things first, you have to set up a GitHub account on GitHub and then download git and Git Bash. I'll share a more detailed guide of this process don't worry. Git Bash is sort of the terminal that we'll use to write our commands while connecting our git to Git Bash. Git runs locally and keeps track of changes during the project while GitHub is an online version that does the same. Depending on your Operating System there are different ways to download Git. Alternatively, VS Code can be used to push your projects to GitHub and that's what we'll focus on, since its the simplest one. At this point I'm assuming we have a project that needs pushing to GitHub.
2. Creating a folder locally
There are shortcuts to create and edit files using Git Bash when doing projects and I thought it best to include them here for posterity and experiment as well.
- mkdir makes a directory/creates a folder eg mkdir Analytics Project
Make sure not to include space on the name of the folder, use hyphens or underscore instead. Alternatively, enclose the name of the folder in quotation marks if spaces are used in naming the folder, then and add the your data set into the folder created.
These commands are useful in Git Bash depending on which stage of the process you are in.
- cd changes to another directory (cd "Analytics Project') cd/path/to/your/repository
- cd .. takes you back to previous directory
- ls lists down what's in the folder
- rm deletes document in the folder
- rm -r deletes the folder in the folder
Creating a README file
- touch creates a README document (touch README.md)
A readme file is important for documenting the process of a project. It usually acts as a contact point with anyone interacting with the your digital product.
On Git bash or terminal, access the folder cd Analytics Project
To edit content in README.md file, we'll use the command echo "Analytics Project" >README.md
To check what is written, we'll use the command cat README.md
Nano can be used to simplify editing. This has to be my preferred method of editing as it is the easiest to use, especially when you are a beginner.
Running the command nano README.md will make a text editor appear where in we shall edit our content.
To Save content, press Control + O,
Press Enter Key to confirm the file, then press Control + X to exit._
3. Git Configuration
This is probably the simplest part of this process after creating a GitHub account. On Git Bash, check user name user email by running
git config --global --list
If the account that exists isn't yours or you'd like to use a different one we can overwrite the existing account by using
git config --global user.name "YourGitHub Profile Name"
Then you'll be prompted to add a passphrase which is basically a password, it's advisable not to write one incase you forget it. So just *ENTER * to move to the next step.
Incase you'd like to change your branch from master to main run;
git config --global init.defaultBranch main
4. Key Generation using SSH
In this part we'll be generating a SSH key that we'll use to connect our Git and GitHub. SSH helps us with security because our computer needs a secure way to prove to GitHub that it is authorized to access our GitHub account
SSH stands for: Secure Shell
With SSH authentication, you create a pair of cryptographic keys.
GitHub requires the public key to be added to your account, while the corresponding private key stays on our computer. Now, this is where things a bit technical.
When we generate an SSH key, you will normally get 2 keys:
- id_ed25519 - private key
- id_ed25519.pub - Public key
But, I'd like us to generate a public key using a shortcut:
ssh-keygen -t ed25519 -C "[email protected]"
Then a prompt to overwrite will appear, write "y" meaning yes and press Enter. If you chose to have a password input, if you didn't press Enter then run
clip < /c/Users/user/.ssh/id_ed25519.pub to save they public key in a file.
Testing
We've already generated a key, now we use an IDE in this case VS Code to push our project to GitHub.
To confirm if we've connected our Git to GitHub using the SSH Key that we have generated. Go to Git Bash terminal and run
ssh -T [email protected]
There shouldn't be any problem with this but if anything isn't seeming right, you can always Chat GPT.
Okay now let's copy our generated key to GitHub
- Open your GitHub account
- Go to settings
- Click SSH and GPG
- Delete and add new or simply add the generated key if there are no keys yet
Using VS Code
You can create a folder or choose a folder through VS Code.
- Go to file
- Open your folder containing your project
- select your folder
Connecting Git to GitHub
Now we'll configure GitHub by;
- Clicking Source control on the left side
- Choose Manage work trust
Initialize repository - this is the equivalent of git innit when using Git Bash. It creates a hidden .Git directory which contains information that our Git uses to track the developments and changes.
Initializing the repository allows our project folder to become a Git Repository.Add change - this is a write up of the content you would like to indicate in present tense eg "Add Dataset". This is analogous to writing git commit -m " ", while using terminal or Git Bash.
Against commit on the far right click the drop down and choose commit and sync. Comparable to this is git push origin main
After pushing our project to GitHub, you can run command Git status to confirm everything is as you wanted it to be and maybe adjust accordingly.
From here you'll see a number of prompts, only click "Always", "Add remote", "Publish Branch", "Allow- if configuring for the first time."
Lastly, choose a browser of your choice and authorize access remembering to chose between creating a public or private key depending on your choice and preference, Sign in and viola, The project is posted on GitHub.
Something to note the name of the repository will bear the name of the folder used.
Conclusion
That's it imagine, there are other ways to push your projects to GitHub if that's something you are interested in , be sure to find that out, there's also a lot more to know in GitHub and GitHub Configuration but baby steps, right? That's all for today all and the best at pushing your projects on GitHub.
Top comments (0)