How to Connect Your Local Project’s Codebase to a GitHub Repository Fast!

GitHub is one of the most powerful tools for developers, whether you are working on your project solo or working amongst members of a team. Git and GitHub adds a version control layer to your code so anyone can see the change history, the edits, and also see various branches of the codebase.

In this episode of the Tech Stack Playbook, we are going to review the process of uploading a local codebase repository from a computer to GitHub from the command line.

This episode is packed with content, so here’s a glance at what you’ll learn about below, and a series of sections further down in this blog post highlighting the important topics we discussed:

Time stamps:
00:00 GitHub 101
02:15 Set up your code project locally
03:20 Create an empty repository in GitHub
04:47 Initialize your GitHub connection locally
10:28 Review the pushed changes in GitHub
10:53 Set up GitHub Desktop to manage our repository
11:33 Push new changes via GitHub Desktop to GitHub
12:57 Wrap-up and reflection on what we set up with GitHub




👨‍💻 GitHub 101


GitHub
is one of the most powerful tools for developers, whether you are working on your project solo or working amongst members of a team. Git and GitHub adds a version control layer to your code so anyone can see the change history, the edits, and also see various branches of the codebase.

I like to think of GitHub as the code-version of Google Docs. You can switch back to a previous version of your document, make edits and push those in real time, and also collaborate with others on the same version of the document.

Another major benefit to GitHub is branching, allowing you to have different states of your codebase for different reasons. A common practice for codebases involves 3 core branches: dev, stage, and prod. The dev branches is what you will use to build from and test, debug, and add in new features. The stage branch is for new additions that are ready for review ahead of going to prod – the reason being, you need to thoroughly test the addition to make sure it is ready for users and so you don’t mess with the client-facing build. The prod, or production, version of your codebase is what is running live for your clients or customers or users. This (hopefully) is free of bugs and errors because of the previous two steps to push code to this stage.

However, if you are working on your project solo, you might only need 2 core branches: main, a version for you to build/test your app, and prod, a version in production that is always live.

In today’s tutorial, we are going to review the process of uploading a local codebase repository from a computer to GitHub from the command line. In each of these below steps, I denote which ones are things you do (local) – on your computer, or (web) – on the GitHub website.



👨‍💻 Step 1: Set up your code project folder (local)

For this example, I have created a ReactJS Soundcloud Clone application with the create-react-app framework and implemented the AWS Amplify framework with Cognito identity and access management, DynamoDB NoSQL database storage, S3 object oriented storage for media items, and AppSync to help us manage a GraphQL API. The app allows users to create an account that then allows them to upload songs to the cloud through the app and then play those media files through the built-in player. Stay tuned for a full-tutorial on this build coming soon ☺️

If you do have a local codebase on your computer that you want to push to GitHub, feel free to jump right into Step 2 below.

If you do not have a local codebase on your computer to push to GitHub, you can spin up a practice repo with either a React.js or NEXT.js template below to get started:

For React, run:

npx create-react-app techstackplaybookpracticerepo

For Next, run:

npx create-next-app --example with-tailwindcss techstackplaybookpracticerepo

Once you have a folder for your app created with one of these frameworks, move onto Step 2 below.



👨‍💻 Step 2: Create an empty repository in GitHub (web)

When you go to https://github.com, at the top right, when you click on your profile avatar, there is a drop-down of menu items.

Click on the drop-down item that says “Your Repositories” which will bring you to a page that lists out all of the repositories in your GitHub account. There will be a green button that says “New” – make sure to click that to pull up the create repository flow.

There will be a number of options to select, but here’s a quick guide:

  • Repository template: (keep default option)
  • Repository name: TechStackPlaybookPracticeRepo
  • Description: (optional)
  • Public/Private: Public
  • Initialize this repository with: (keep these options unchecked)

When you are ready, click “Create repository” to finalize the setup of an empty repository in GitHub.

When the empty repository page loads, the link will look something like this: https://github.com/YourGitHubHandle/TechStackPlaybookPracticeRepo

You will notice on this page, there is a URL that will be to the right of the HTTPS button. It will look like this: https://github.com/YourGitHubHandle/TechStackPlaybookPracticeRepo.git. You will want to copy this URL down as we will need it in Step 3 later on.



👨‍💻 Step 3: Initialize your GitHub connection (local)

From the root of your project folder (the outermost folder that wraps everything, for me this is called soundcloud which contains my /amplify folder, /public folder, /src folder, etc.), make sure that your terminal window is set at this level.

You will initialize an empty git repository with a branch called main with the following:

git init -b main

This will create a hidden folder called .git which will actually save and store all of our version control changes. It’s almost like a cookie that connects our local repository to the GitHub version.

Next, we add our locally created files to this .git file with the following:

git add .

We then want to commit these files we’ve added onto main to our specific repository that we are initializing for GitHub with:

git commit -m “First Commit to GitHub”

This will probably add a lot of files listed out. Make sure that .gitignore is included in this list of added files and includes node_modules so that you don’t upload a gazillion node_modules files to GitHub ☺️

In the github.com page with the URL that we copied down in Step 2, we will now use this to send our github files to this URL endpoint:

  • make sure to change YourGitHubHandle to your actual account:
  • make sure to change TechStackPlaybookPracticeRepo to the name of your actual repo you created on GitHub
git remote add origin https://github.com/YourGitHubHandle/TechStackPlaybookPracticeRepo.git

What this is effectively doing is telling git that, from the remote local version of our repository, we are going to add all of those files to the origin of this empty GitHub repository link online on the web.

We will now set the new remote with this:

git remote -v

You will then see that there are 2 lines printed in the terminal, one that ends with (fetch) and one that ends with (push). We are calling this GitHub repository and pushing our code locally from the remote to GitHub in the cloud.

Now that we’ve initialized the connection, we will push our code locally to the origin main which we’ve set as the destination in GitHub:

git push -u origin main

This will enumerate all the objects we want to push, it will then get compressed into threads to push them and will push to this GitHub link which is the one we want for this repository and the branch is set as one called main and sets it to track it from origin.



👨‍💻 Step 4: Review the pushed changes in GitHub (web)

On our GitHub repository page (https://github.com/YourGitHubHandle/TechStackPlaybookPracticeRepo), what was once empty, upon refreshing the page, should now show our codebase that we had locally on our computer now on this web page.

What we have done is create a synced pair between our local repository (remote) and our GitHub repository (origin). However, this is just for our most recent changes on our local repository. What if we want to create ongoing pushes to our GitHub repository and do regular pushes as a backup to GitHub? We will review this with a tool called GitHub Desktop in the next step below.



👨‍💻 Step 5: Set up GitHub Desktop to manage our repository (local)


GitHub Desktop
, a Microsoft-created GitHub manager, is a GUI (graphical user interface) client/platform that creates an easy and efficient way to manage our GitHub repository right from our computer without needing to worry about typing the right command line scripts and sequences in the terminal.

While it is very important to understand what is happening behind the scenes at the terminal level, for us to move fast, we need tools and ways to expedite and automate our work flow processes. When you are typing in the terminal, spelling errors and human error can cause us to make mistakes, errors, or lose precious time. GitHub Desktop helps developers move faster with their repositories and has been an amazing tool in my workflow.

As a side note, there are other GUIs for Git and SCM (source control management) tooling, such as Kraken which is optimized for Azure DevOps, as well as GitLab.

We will need to create a new repository in our GitHub Desktop client because while the repository is synced with github.com, our GitHub Desktop client wouldn’t have been updated to track this repository yet until we allow it.

In the “Add” drop-down on the button to the right of the text field in the GitHub Desktop client, you will select the drop-down option: Add Local Repository

When we have the option to “Choose” a folder, we will want to select the outermost folder container for our project. For you, this might look like: /user/Documents/GitHub/TechStackPlaybookPracticeRepo

Once the outermost folder is selected, we will click Add Repository

This will now connect to our hidden .git file and anytime we make changes and save them in our code editor, GitHub Desktop will show those changes reflected in the GUI.



👨‍💻 Step 6: Push new changes via GitHub Desktop to GitHub (local)

In GitHub Desktop, we should see 1 or more file changes reflected in the list of “changed files” on the left half of the app. In this video, I updated the README.md file, so that is why it has a check-mark next to README.md and the app says 1 changed file at the top.

In the bottom right, we will give our commit a name, which can be anything you wish. I said: Updated Readme for YouTube!. You can also write a description if you want, but it is optional.

At the top, you will see I have the current branch set to main, as I only have 1 branch created for this video.

When everything looks good, you will click the blue bottom at the bottom left that says “Commit to main`

The bottom right button should now say Push origin, and once you select this, it will send those updated changes committed to our local remote branch to the main GitHub branch on the web.



👨‍💻 Step 7: Review the pushed changes in GitHub (web)

On our GitHub repository page (https://github.com/YourGitHubHandle/TechStackPlaybookPracticeRepo), upon refreshing the page, you should see your changes reflected in the online version of the codebase, matching your changes locally as well.

In this example, the README.md file reflects the change and in the file/folder list, you will see that all the folders/files have the commit message First Commit to GitHub from Local except for one, which is that README.md file. It has a message that reads the same message we put into GitHub desktop: Update Readme for YouTube!

Check out the full recording below:


Let me know if you found this post helpful! And if you haven’t yet, make sure to check out these free resources below:

Let’s digitize the world together! 🚀

— Brian




Source link

Multiple GitHub accounts on one laptop

Imagine the next situation:

  • You have only one laptop
  • You have your personal GitHub account
  • Your employer stores code on GitHub as well
  • You need to commit your personal code to your personal repositories but also work code to the employer`s repositories.
  • You can`t do this from your personal account but do not want to create an additional one (with corporate email)

What to do in this situation? There is a way, how you can configure your laptop to commit to work repositories with work credentials, and to personal one with your personal one.

This solution is based on 2 aspects:

  • correcting SSH config
  • git URL re-writing

The main advantage of this approach is that it doesn’t require any additional work to get it right. You will not need to change remote URLs or remember to clone things differently. The second part ( the URL rewriting) will take care of it.

First of all, let’s correct our .ssh config. Assuming you have 2 ssh keys, your personal (github_personal) and your work (github_work). How to create ssh keys you can read in the GitHub docs.

~/.ssh/config

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_personal

# Work GitHub
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_work

Host *
  AddKeysToAgent yes

Both this configs have same user and domain, but we will take care about it later. Next – global git config.

~/.gitconfig

Here we need to add our default name and email (the one we used in ssh creation for our personal account)

[user]
    name = My Name
    email = personal@personal.email

[includeIf "gitdir:~/path/work_dir/"]
    path = ~/path/work_dir/.gitconfig

[url "github-work:work-github-org-name/"]
    insteadOf = git@github.com:work-github-org-name/

What happens here? First, set our default name and email. Second, we point to use local .gitconfig file for all repositories located by mask ~/path/work_dir/. And the last, replace github.com (default account for Github) with the profile we set under github-work in .ssh/config.

The last part is modification of local .gitconfig for all our working repositories:

~/path/work_dir/.gitconfig
It is easy – just replace your email with your corporate one.

[user]
    email = work@work.email

That is all! As long as you keep all your work repos under ~/path/work_dir/ and personal stuff elsewhere, git will use the correct SSH key when doing pulls/clones/pushes to the server, and it will also attach the correct email address to all of your commits.

How to check? Clone repository via SSH, cd to that folder and execute git config --get user.email


Source link

Step by step guide to minting your Git commit as an NFT

This will be my first article around NFT’s and anything related to Web3.
Not because I’m not interested, but because it’s all new to me as well.

If you found this article, it most likely means you are interested in it, so no need to discuss if it’s good or wrong here.

By the end of this article, you will have converted a Git commit you made into an NFT!
This NFT will define such memorable moments in a code project’s history, which is super exciting.

Think about GitHub’s artic vault, a collection of remarkable contributions that will live on long after the code is gone.

And this is precisely what our NFT will do.
Small note, it only works with public repo’s.

The one I made looks like this:

NFT of my commit

Or you can view it on OpenSea



Using MetaMask

Visit the MetaMask website and follow the install instructions for your browser.

After installing the extension, it automatically pops up on this landing page.

MetaMask landing page

Note: Take 5 minutes to play with this fox. It’s adorable and follows your mouse around. 🦊

On the next screen, you will import an existing wallet or create a new one.

If you have an existing one, you’ll know what to do, so let’s make a new one.

Make a new wallet

You’ll have to agree to their terms and conditions, and in the step after that, you’ll have to create a secure password.
Preferably use a password manager for this.

Choose a secure password

The step will show you a video and the importance of the secret recovery phrase.
Take good note of what is explained here. It’s super important.

Note: Never share this secret phrase, and don’t lose it! It’s the only way to enter your wallet! 🆘

Click the lock, and write down the phrase here. It’s super important you write this down or save it in a super-secure location before going on.

Viewing the secret passphrase

On the screen after this one, you’ll have to type the phrase by choosing from random words.
Make sure this matches the phrase you just noted down.

MetaMask phrase

Once you fill out the phrase, click next, and you’ll be done with the MetaMask setup.

MetaMask setup done



How to mint the commit NFT

Luckily for us, there is already a fantastic website that will do the heavy lifting.

So step one, go to the GitNFT website.

Visit the GitNFT website

Now you can press the Login button on the top right and login
with your GitHub account.

Login to GitNFT

Once logged in, you can click on the “Suggest or Mint” button or view your recent commits by clicking “My commits”.

Suggest or Mint a new NFT

Now head over to GitHub to find the commit you want to turn into an NFT.
For me, it’s the first commit for daily.dev, where I introduced the settings dropdown menu! 🤯

My first commit

Copy the URL, and paste it on the GitNFT website.

Getting the NFT

Once it’s loaded, click the “Mint commit” button at the bottom.

This will automatically pop-up MetaMask to connect to GitNFT. You can click next there.

Allow GitNFT access to MetaMask

You can enter a description that can say something about the commit on the page itself.
And you can toggle between Dark and Light mode.

Needless to say, I love dark mode 🖤

Once you are happy, click the “Mint commit” button.

Mint a GitHub commit

Once you click this button, it should pop up MetaMask again, where you’re asked to sign the minting.

Sign the mint

It will then load for a couple of seconds and eventually redirect you to the minted NFT.
(Have some patience here, it can take some time)

Once done, you’ll see your NFT!
You can also open it on OpenSea, and see the progress on EtherScan.

Git commit into NFT

And that’s it!
We turned a Git commit into an NFT.

Hoped you enjoyed it and looking forward to seeing some cool NFT’s show up.



Thank you for reading, and let’s connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter




Source link

Rare & useful Git commands summarized + solution to difficult scenarios while using Git



Git commands

  • git restore . – restores the files to the previous commit/ undos all the local changes that haven’t been commited.

  • git restore index.html – restores only that particular file to the recent commit/ undos all the local/uncommited changes for that file.

  • git reset --hard <hash code of the commit> – removes commits and goes back to the commit for that hash code

  • git reset --source <hash code> index.html>– removes commits and goes back to the commit for that hash code only for that particular file.

  • git commit --amend -m 'Your message'– helps re-write messages

  • git revert <hash code>– helps to roll back to a previous commit by creating a new commit for it. Doesn’t removes those commits from the log like git reset does.

  • git reflog– this can be useful to bring back deleted commits/files/changes. Use git reset <hash code of lost commit from reflog> to bring back rolled changes.

  • git reset HEAD~2– Helps roll back by 2 commits and unstage all the changes in those 2 removed commits.

  • git reset HEAD~2 --hard

  • git rebase (most useful command)- Reapply commits on top of another base tip. ex. git rebase master sets the branch at the tip of master branch



Moving commited changes to a new branch: (scenario: you accidently worked on master)

  • – Use git checkout -b new-feature
  • – Then roll back commits on master using git reset HEAD~1 --hard: (this command will roll back 1 commit)



Stashing-

  • Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
  • The modifications stashed away by this command can be listed with git stash list, inspected with git stash show, and restored (potentially on top of a different commit) with git stash apply. Calling git stash without any arguments is equivalent to git stash push.

  • git stash

    • stashes/ saves the changes in the back of the project/ another directory of the project and the control moves back to the last working copy of the last commit.
    • saves the changes as a draft and moves back to code of the last commit
  • git stash push -m "Message"– Adds a message for the stash to the stash list

  • git stash list – lists all the draft changes in the back of the project

    Tip- The stash list stores all the stashes and each stashed feature/code has a unique index number to it. The last added stash always appears at the top with index 0.

  • git stash apply – applies the last stashed draft to our current working directory

  • git stash apply <index number> – applies the particular indexed stash to our current working directory

  • git stash drop <index number> – drops the stash out of the stash list with the particular index

  • git stash pop– pops the last draft changes back into the working directory/ on the working branch and that draft is then removed from the stash list

  • git stash pop <index number>– pops the draft change with the particular index back into the working directory/ on the working branch and that draft is then removed from the stash list

  • git stash clear– clears/ deletes all the draft changes stored



Moving commited changes to an already existing branch using cherry-pick:

  • git checkout feature-branch
  • git cherry-pick <hash code of that commit on master>
  • git checkout master
  • git reset HEAD~1 --hard (rolls back 1 commit)



Squashing commits-

  • git rebase -i <hash code of the commit above which all the commits need to be squashed>
    • i stands for interactive squash
    • opens up squashing in vim editor where you can pick or squash and update commit messages

Source link

Some GitHub Terms You Should Know!

GitHub is one of the most used hosting platform for version control and collaboration, we must have heard about the terms like repo and PR in your coding career what do they mean, or simply put what do they even mean to us? here are a few Github terms you must know!



Repository (Repo)

it is a directory that stores all of the files and folders you used to build the project and it also stores the changes made to the project.



Commit

commit is a change that you bring to your program, it can be adding, removing, modifying code or files from your project.



Local and Remote

your project will have two independent repos one which is offline is called Local and one which is hosted online on platforms like GitHub or GitLab is Remote



Pull, Push or Fetch

to synchronize your project between local and remote we use these three operations.

Pull – pull changes from remote to local

Push – push changes from local to remote

Fetch – only downloads new data but doesn’t integrate it to your working project in local



Branch

they basically divert you from the mainline of development, so that you can fix the bug or build a new feature and then merge it back without messing up the main code.



Pull Request

it is simply a way of telling people that you want the changes you made in the branch to get included in Main Code.


Source link

How To Show Your Latest Blogs On GitHub Profile

As a developer, we love to build our online presence and for that, we do a lot of things like sharing tips and tricks, writing in-depth guides to discuss any tech, writing tutorials on how to build x with y and all.
we use different platforms to share content like hashnode, dev community, medium, etc. like I do, I create content on hashnode and cross-post on other platforms.

while sharing my content on other platforms I got a thought what if I can show my latest content on my GitHub profile? if people are visiting my GitHub profile and from there if they get to know my latest content that would be great right. so I started looking for how I can show my latest blogs on my GitHub profile. I found two solutions (two GitHub Actions) that we will be discussing in this article.

before jumping into solutions let’s first discuss what are GitHub actions and what they are used for.



What is GitHub actions

GitHub actions are a set of events and workflow, whenever specified events happen to your GitHub repository it will run the associated workflow for it.

want to learn more about Github actions, you can get started from here


Let’s discuss two GitHub workflows that I used to show my latest blogs on my Github profile.



Blog Post Workflow

Using this workflow we can show blog posts from any source in our Github Profile Readme automatically using RSS feed. we can also use this workflow to show StackOverflow activity or Youtube Videos.



Setting up workflow

we can easily set up this workflow in our profile repository to fetch and show the latest blogs automatically using the RSS feed.



Create the .github folder in your profile repository if it does not exist.

> mkdir .github



Create the workflows folder inside the .githubfolder if it does not exist.

>mkdir .github/workflows



Create the workflowname.yml file inside workflows folder.

where you can replace workflow name with your workflow name. I will give a blog-post.yml.

> touch blog-post.yml

after creating a workflow file add this content to it.

name: Latest blog post workflow
on:
  schedule: # Run workflow automatically
    - cron: "0 * * * *" # Runs every hour, on the hour
jobs:
  update-readme-with-blog:
    name: Update README with latest blog posts
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master
        with:
          max_post_count: 10
          feed_list: "https://blog.sachinchaurasiya.dev/rss.xml"



Here we have three main components of the workflow

  1. name
  2. on
  3. jobs

Let’s discuss them one by one

  • name is the name of the workflow after workflow run If you see the actions tab in your repository you will get workflow runs like this.

image.png

  • on is used for defining what action you want to run this workflow.

here we are running this workflow on schedule using corn job to run this workflow automatically every hour.

If you don’t know much about corn syntax this may be helpful for you
The quick and simple editor for cron schedule expressions

  • jobs is used for defining what to do when an event happens on our repository.

here we are defining only one job that is update-readme-with-blog which will commit on our repository with the message Update README with latest blog posts.

for jobs, we will need to define what environment it will be running and we are running this job on ubuntu.
also, we will need to provide what steps to use like this

      - uses: actions/checkout@v2
      - uses: gautamkrishnar/blog-post-workflow@master

if you notice we are using the with attribute for 2nd action that is gautamkrishnar/blog-post-workflow@master
here we are providing 2 options max_post_count and feed_list.

Please Replace the above feed list URL with your own RSS feed URLs

Now, I hope we are clear with all the components of a workflow.



Last but not least add this content to your profile README.md file.

# Latest Blogs
<!-- BLOG-POST-LIST:START -->
<!-- BLOG-POST-LIST:END -->

Think of it like a block that will get replaced by your blog list.

For Example :

# Latest Blogs
<!-- BLOG-POST-LIST:START -->
- [The Simple Guide to Seo For Your Application](https://blog.sachinchaurasiya.dev/the-simple-guide-to-seo-for-your-application)
- [5 Awesome Libraries To Use In Your Next ReactJs Project](https://blog.sachinchaurasiya.dev/5-awesome-libraries-to-use-in-your-next-reactjs-project)
- [An Introduction to Python Dictionary and Structuring Data](https://blog.sachinchaurasiya.dev/an-introduction-to-python-dictionary-and-structuring-data)
- [How to Setup MongoDB Atlas?](https://blog.sachinchaurasiya.dev/how-to-setup-mongodb-atlas)
- [Some of the Best Open-Source Projects to make your life easier.](https://blog.sachinchaurasiya.dev/some-of-the-best-open-source-projects-to-make-your-life-easier)
- [What are Views in Django?](https://blog.sachinchaurasiya.dev/what-are-views-in-django)
- [Django project vs app](https://blog.sachinchaurasiya.dev/django-project-vs-app)
- [Mvt Pattern Of Django](https://blog.sachinchaurasiya.dev/mvt-pattern-of-django)
- [Simple Guide for Django Admin Interface](https://blog.sachinchaurasiya.dev/simple-guide-for-django-admin-interface)
- [Understanding Django Application LifeCycle.](https://blog.sachinchaurasiya.dev/understanding-django-application-lifecycle)
<!-- BLOG-POST-LIST:END -->

The second workflow is specific to the hashnode platform, so let’s also discuss it.



Hashnode Blog

Using this workflow we can fetch our hashnode publication blogs and show them to our GitHub profile.



Setting up workflow

we can easily set up this workflow in our profile repository to fetch and show the latest blogs automatically using the RSS feed.



Create the .github folder in your profile repository if it does not exist.

> mkdir .github



Create the workflows folder inside the .githubfolder if it does not exist.

>mkdir .github/workflows



Create the workflowname.yml file inside workflows folder.

where you can replace workflow name with your workflow name. I will give a hashnode.yml.

> hashnode.yml

after creating a workflow file add this content to it.

name: "📚 latest Blog"

on:
  workflow_dispatch:
  schedule:
    - cron: "0 */24 * * *" # Runs Every 24 Hours

jobs:
  update_blogs:
    name: "Update With Latest Blogs"
    runs-on: ubuntu-latest
    steps:
      - name: "📥  Fetching Repository Contents"
        uses: actions/checkout@main

      - name: "📚  Hashnode Updater"
        uses: "varunsridharan/action-hashnode-blog@1.1.1"
        with:
          USERNAME: "Sachinchaurasiya" # Hashnode Username
          COUNT: 4 # MAX Visisble
          STYLE: "blog-left"
          BLOG_URL: "https://blog.sachinchaurasiya.dev/"
        env:
          GITHUB_TOKEN: $ secrets.GITHUB_TOKEN 

Here all the components are the same as we discussed earlier, except here we have some additional and different attributes like

  • USERNAME – your Hashnode username
  • COUNT – post count you want to fetch
  • STYLE – how you want to list out your blogs
  • BLOG_URL – your hashnode publication URL.

One different thing we have here is env which is used for automatic token authentication.
you don’t need to worry about secrets.GITHUB_TOKEN will automatically get referred from your GitHub account.

env:
    GITHUB_TOKEN: $ secrets.GITHUB_TOKEN 



Add placeholder content to your profile README.md file.

# Latest Blog Posts 👇
<!-- HASHNODE_BLOG:START -->
<!-- HASHNODE_BLOG:END -->

Think of it like a block that will get replaced by your blogs.

For Example:

image.png



Summary

  • We discussed what is GitHub actions and the workflows to use it.
  • We also discuss two GitHub actions using which we can show the latest blogs on our GitHub profile.
  • I am using 2nd one that is Hashnode Blog actions because I first publish all my content on Hahsnode.
  • Which action you will be using or already used let me know in the comment section

And that’s it for this topic. Thank you for reading.



Connect with me

LinkedIn | Twitter




Source link

How to delete remote commits in git?

Assume you have pushed commits in order A1 => B2 => C3 in remote repository.

Now you want to delete commits C3 and B2.

The simple solution is as follows using git reset

 git reset --hard <A1-commit-id>
 git push -f origin <branch-name>

However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes C3 and B2.

That’s where git revert comes in

git revert --no-commit C3
git revert --no-commit B2
git commit -m "commit message for your reverts"

Source link

Please remove that .DS_Store

macOS automatically creates .DS_Store when you open a folder with Finder, the default file manager. The operating system stores some information in binary in this file, for example, the list of files inside the folder.

You cannot read a .DS_Store file just by opening it (binary data), but it’s pretty easy to decode. If for some reason, the file gets deployed to a webserver, things can turn nasty:

  • it might disclose some information such as the name of some removed files as .DS_Store files are only updated by Finder
  • it might also be used to download files recursively from the webserver 🔥

How the heck can you deploy such files on production?

It happens more often than you might think, for example, when you don’t ignore .DS_Store files in your project’s .gitignore. I see it very frequently, including in public repositories.

The best approach, to me, is to configure it globally on your machine. This way, even if you forget to ignore those files in your particular project, it will be skipped anyway.

The following command will locate your global .gitignore file:

git config --global core.excludesfile  

Open it and verify that .DS_Store files are in the list.

If the ignore file does not exist yet, create a .gitignore file at the root of your home directory and run this:

git config --global core.excludesfile ~/.gitignore

It will set the file as the global ignore file. You can find plenty of templates on the web to get a robust list for various usages.

To list and remove potential existing .DS_Store in your repository:

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Be safe.

Photo by Giorgio Trovato


Source link

Basic Git cheat sheet (yet another)



Yet another Git cheat sheet.

This sheet only contains the basics of git like committing, viewing, cloning, removing, etc
Well to guys who gonna comment down, look at this duuuude…posting another cheat sheet, just move on bro.
Anyways I hope you’ll like this cheat sheet <3



Creating Snapshots

Initializing a Repository
Initializing – git init

Staging Changes/Files
Stages a single file – git add file1.js
Stages multiple files – git add file1.js file2.js
Stages with a pattern – git add *.js
Stages the current directory and all its content – git add .

Unstaging Changes/Files
Copies the last version from repo – git restore –staged file.js

Viewing Status
Full status – git status
Short status – git status -s

Viewing the staged/unstaged changes
Shows unstaged changes – git diff
Shows staged changes – git diff –staged

Skipping the staging area
git commit -am “Message”

Removing files
Removes from working directory and staging area – git rm file1.js
Removes from staging area only – git rm –cached file1.js

Renaming or moving files
git mv file1.js file1.txt (first old name, new name)



Browsing History

Viewing history
Full history – git log
Full history from oldest to newest – git log –reverse
Shows the list of last modified files – git log –stat
Shows the actual changes – git log –patch

Viewing the history of a file
Shows the commits that touched file.txt – git log file.txt
Shows statistics (the number of changes) for file.txt – git log –stat file.txt

Filtering history
Show last 3 changes – git log -3
Filter by author – git log –author=”Gourav”
Filter by date – git log –before=”2022-01-20″
Filter by files modified (commit in which there are changes in file.txt) – git log file.txt
Show Commits with “Fixed” in their message – git log –grep=“Fixed”



Branching & Merging

Managing branches
Creates a new branch called alpha – git branch alpha
Switching branch to alpha – git switch alpha
Deleting branch alpha – git branch -d alpha

Merging
Merges the alpha branch into the current branch – git merge alpha
Aborting merge – git merge –abort

Viewing the merged branches
Shows the merged branches – git branch –merged
Shows the unmerged branches – git branch –no-merged

If you think there’s something wrong or I missed related to these types, please comment below. Thanks.
Hope you found this helpful <3


Source link

Git shortcuts (alias)

Shortcuts and aliases I was compiling as I was setting up a new laptop, and thought I’d share them.



Lets get situated with where we are starting

$ cat ~/.gitconfig

[user]
        name = Foo Bar
        email = example@example.com
[init]
        defaultBranch = main
[alias]
        co = checkout
        br = branch
        ci = commit



Git Shortcuts: (1) Git alias or (2) Git+Shell alias

  • Make git shortcuts in a git alias – pattern (note: –global is normally used for a dev’s user account, but you could use –system for all accounts, –local for the local repo only)

$ git config --global alias.<alias> <commands>

  • Make git shortcuts in shell (bash/zsh etc.) alias – pattern

$ alias <alias>='<commands>'

Example: use shortcut “gl” to list git user aliases, including adding, listing and removing the alias.

$ git config --global alias.gl 'config --global -l'

$ git gl

[...]
init.defaultbranch=main
alias.co=checkout
alias.br=branch
alias.ci=commit
[...]

$ alias gconf="git gl"

$ gconf

[...]
init.defaultbranch=main
alias.co=checkout
alias.br=branch
alias.ci=commit
[...]

$ alias -p

alias gconf="git gl"

$ unalias gconf

$ gconf
bash: gconf: command not found

$ alias -p

Use could also use this to see settings:

git config --list

file:/Users/foobar/.gitconfig  alias.com=checkout main
file:/Users/foobar/.gitconfig  alias.p=push
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=tru

$ git config user.email

example@example.com

$ git config user.name

Foo bar

$ git config --global user.email "myname@gmail.com"

$ git config --global user.name "firstname lastname"



Basics

$ git config --global alias.co checkout

$ git config --global alias.com "checkout main"

$ git config --global alias.br branch

$ git config --global alias.a add

$ git config --global alias.cm 'commit -m'

$ git config --global alias.p push

$ git config --global alias.mr merge

$ git config --global alias.rb rebase

$ git config --global alias.rbc rebase --continue

$ git config --global alias.st status

$  git st

On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        git-aliases.md

nothing added to commit but untracked files present (use "git add" to track)



Git Reset

Important: do not use this config unless you are sure you know what you are doing, it could result in losing code permanently if you misuse this or make a mistake.

Use a test repo first, until you are sure about what is going on.

see: What’s the difference between git reset –mixed, –soft, and –hard? https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard

As stated in the link above:

--soft: uncommit changes, changes are left staged (index).
--mixed (default): uncommit + unstage changes, changes are left in working tree.
--hard: uncommit + unstage + delete changes, nothing left.

Undo last local commmit, to HEAD (uncommit, keeps in stage)

$ git config --global alias.rs reset --soft HEAD~1

Undo last local commmit, to HEAD (uncommit unstage)

$ git config --global alias.rmx reset --mixed HEAD~1

Undo local edits to HEAD (DANGER, permanent, caution)

$ git config --global alias.rh reset --hard HEAD~1

List of all commits – summary

$ git config --global alias.l1 'log --oneline'

61eee34 (HEAD -> main, origin/main, origin/2-first-app-counter, 2-first-app-counter) Counter app
e9a23b9 (2-first-app) Hello world
bcc8bf2 Start fresh
abf9f0a (origin/1-hello-world, 1-hello-world) Basic hello world

Last commit

$ git config --global alias.last 'log -1 HEAD --stat'

git last

Author: Foo bar <example@example.com>
Date:   Fri Dec 31 14:54:47 2021 -0800

    Counter app example

 counter.sol | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Remote comfigured repos

$ git config --global alias.rv 'remote -v'

$ git rv

origin  https://github.com/foobar/Hello-World.git (fetch)
origin  https://github.com/foobar/Hello-World.git (push)

Search for specific strings (put string after -F)

$ git config --global alias.se '!git rev-list --all | xargs git grep -F'

Cherry-pick

more info: https://www.atlassian.com/git/tutorials/cherry-pick

$ git config --global alias.ch cherry-pick

Change the commit message:

git config --global commit.template ~/.gitmessage.txt


Source link