Skip to main content

GitHub

Updated 4 min readMarkdown

Before diving into Git and GitHub, we have to know some basic terminology. There is a term called source code management, and it has two types.

CVCS - Centralized Version Control System.

DVCS - Distributed Version Control System.

Centralized Version Control System.

  • It is not locally available, meaning we need to be connected to a network to perform any action.

  • Since everything is centralized, if the central server fails, you will lose the entire data.

Distributed Version Control System

  • In DVCS, every contributor has a local copy or clone of the main repository, i.e- everyone maintains a local repository of their own, that contains all the files and metadata present in the main repository.

Why do we need Source Code Management as DevOps engineers?

To use the CI/CD pipeline in DevOps, you must have the most recent project updates on hand. Because DevOps monitors the most recent code and creates definitions that execute a variety of tasks by user needs, the release definitions that assist in deploying the most recent binaries on your primary environment also use these definitions. Any end server where the finished product is made ready for use might be your client's computer, the production environment, or both.

Important Terms

Repository:

  • A repository is a place where you have all your codes or kind of folder on the server.

  • It is a kind of folder related to one product

  • Changes are personal to that particular repository.

Tags

Tags assign a meaningful name to a specific version in the repository. Once a tag is created for a particular save, even if you create a new commit, it will not be updated.

Push

Push operations copy changes from a local repository server to a remote or central repository. This is used to store the changes permanently in the git repository.

Pull

The pull operation copies the changes from a remote repository to a local machine. The pull operation is used for synchronization between the repositories.

Basic Git commands

  • Initialize an empty Git Repository
git init
  • Show the status of your Git repository.
git status
  • Git stages

  • To add a file to the staging area.
git add <filename>
  • Commit all the staged files to git
git commit -m "<your commit message>"
  • Once we commit our file to git, it will be stored in git. If, by any chance, this file is deleted from our server or laptop, then there is a chance to get it back. In this case, we will see the log file by running the following command, and we will see how to restore the deleted file.

  •     git log
    
  • Now go to the status and see the instruction, like the following command.

git restore <file_name>
git restore <folder_name>
  • Set global username and email for Git (locally)
git config --global user.name "<your username>"
git config --global user.email "<your email>"

Note: Username: Your Github account username.

user-email: Github account gmail

  • Clone an existing Git Repository.
git clone <repository_url>
  • Now send a local file or folder to the git repository.
git remote -v
  • Add remote origin URL
git remote add origin <your_remote_git_url>

Note: Copy the remote URL of your repository.

  • Push your local changes to the remote branch
git push origin <branch_name>

Note: It will require a username and password. For this

Username: your github login username

Password: Go to the account settings > Developer Settings > personal access tokens > Tokens (Classic) > Generate a new token.

Now use thi spassword.

Note: Run git remote -v and see there are two origin links It means that your origin has been added. Now you can push your files or folders to this origin.

  • Create a new branch
git branch <branch_name>
  • For going to a specific branch or changing branches.
git checkout <branch_name>
  • Show the branches of your Git repository
git branch
  • Checkout a new branch
git checkout -b <branch_name>
  • Checkout an existing branch
git checkout  <branch_name>
  • Remove a branch from Git
git branch -d <branch_name>
  • Remove remote origin URL
git remote remove origin
  • Fetch all the remote branches
git fetch
  • Pull your remote changes to the local branch
git pull origin ybranch_name>
  • Check your git commits and logs
git log

Command for branch

  • To show all branch.
git branch
  • Delete Branch
git branch -d <branch_name>

Command For branch merge

  • We can not Merge branches of different Repositories.

  • We use the pulling mechanism to merge branches

git merge <branch_name>
  • git remote set url
git remote set-url origin https://<token>

About the author

  • I am pursuing a Master's in Communication Systems and Networks at the Cologne University of Applied Sciences, Germany.

No comments yet. Be the first to comment.

More from this blog