Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 18, 2021 03:00 pm GMT

Github - A Developer World

whenever you hear this word 'github' from a developer or your friends so a question pops up in your head 'what is github' 

What is Github?

Github is a provider of internet hosting for software development and version control using Git. It offers the distributed version control and source code management functionality of Git, plus its own features. so normally it helps developers to learn and contribute their work in internet.so this is the work of github and you might heard the word repository

What is repository?

A repository contains all of your project's files and each file's revision history. You can discuss and manage your project's work within the repository.
so this is repository it helps us to keep record of our work.

what are alternatives of github?

Top 5 Alternatives To GitHub
Bitbucket.
GitLab.
Google Cloud Source Repositories.
Phabricator.
RhodeCode.
so these are the alternatives which I explored which quite well function but they are less popular mostly in github most of the opensouce contribution are done. Now you quite well know about github and its uses now you might be curious what are the commands in github.

What are top git commands are used always?

Top Git Commands for Developers :

1.Git Init
2.Git Clone
3.Git Branch
4.Git Checkout
5.Git Add
6.Git Commit
7.Git Push
8.Git Pull
9.Git Diff
10.Git Stash
11.Git Status
12.Git Log
13.Git Merge

Let's jump in and look at each of them in detail.

  1. Git Init

The git init command is usually the first command youd run in any new project that is not already a Git repository (also commonly called repo).

It can be used to convert an existing, un-versioned folder into a Git repository. Also, you can use it to initialize an empty repo.

Using Git Init Command

cd into the directory you want to initialize.

Then, run this command.

$ git init

This will transform the current directory into a Git repository. A .git sub-directory will be added. This will allow you to start recording multiple versions of your project.

Note: Running git init on an already initialized directory will not override any of your settings.

  1. Git Clone

The git clone command is used to download the source code from a remote repository (like GitHub, Bitbucket, or GitLab).

Using Git Clone Command

$ git clone (https://url-of-the-repository)
When you clone a repo, the code is automatically downloaded to your local machine.

As a convenience, the downloaded version is linked to the origin (the repository from where you downloaded). I say this is a convenience because when youre collaborating on the same project, youd want to push your changes (more on that below) to a single repo.

But sometimes, people wouldnt want to have this link. If your use case is similar, run

$ git remote rm origin
This will disassociate the downloaded current repository from the origin.

  1. Git Branch

Branch is one of the most important functionalities of Git. This allows teams to work on the same code base in parallel. It enables teams to create Git Workflows and make their workflows more efficient.

Say, youre working on Feature A. And your teammate is working on Feature B. By creating a separate branch for each feature, both of you can work on the same code base in parallel without having to worry about conflicts (at least while youre writing the code).

You can use this command to create a new branch, view existing branches, or delete a branch.

Using Git Branch to create a new branch

$ git branch (branch-name)
This command will create a new branch only in your local system. If you want this to be visible to all the members in the repo, youll still have to push the branch.

To push a newly created branch, run git push -u (remote) (branch-name)

Command to view all branches

$ git branch

or

$ git branch --list
Git command to delete a branch

$ git branch -d (branch-name)

  1. Git Checkout

A mistake I often made when I first started learning git commands was forgetting to switch to the new branch I just created. Yes, after you create a branch, youll have to switch to it with another command. Thats where the Git Checkout command comes in.

Using Git Checkout Command

$ git checkout (branch-name)
This will automatically switch you to the branch name you mentioned in the command.

However, when switching from one branch to another, you need to keep two things in mind:

If you made some changes in the previous branch, you will have to first commit and push them (Ill cover this command below) to your remote repo.
The branch you want to switch must be present in your local system. If not, you can pull them (covered below).
If youre as lazy as I am, Im sure youd want one single command that will both create a new branch and automatically switch to it.

The below command does exactly that.

$ git checkout -b (branch-name)

  1. Git Add

Every time you create a new file, delete it, or make a change, youll have to tell Git to track it and add it to the staging area. Otherwise, the files you made changes to wouldnt be added when you try to push your changes.

Using Git Add Command

$ git add (file-name)
This command will add only a single file to your next commit. If you want to add all the files to which changes were made, you can use

$ git add -A
Its important to remember that using git add will not make any changes in the remote repository. Your changes will be recorded only when you commit them.

  1. Git Commit

Think of Git Commit command like a checkpoint in your development process.

Its commonly used to save your changes. Maybe after completing a specific work item assigned to you in your agile tool.

Every time you commit your code changes, youll also include a message to briefly describe the changes you made. This helps other team members quickly understand what was added, changed, or removed.

Using Git Commit Command

$ git commit -a
This will commit all the changes in the directory youre working in. Once this command is run, youll be prompted to enter a commit message.

Alternatively, you can enter the commit message in the command itself and skip the additional step where youll be prompted to enter the commit message.

To do this, run the following git command:

$ git commit -am (commit-message)
Note: The git commit command saves the changes only in your local repository. It does not push to the remote origin and make your changes accessible for others to collaborate.

  1. Git Push

To make all your committed changes available to your teammates, youll have to push them to the remote origin.

Using Git Push Command

$ git push (remote) (branch-name)
Its important to remember that git push command will upload only the changes youve committed.

  1. Git Pull

Of course, youd want to have the latest updates from teammates as well!

The git pull command allows you to fetch all the changes that your teammates pushed and automatically merge them into your local repo.

Using Git Pull Command

$ git pull (remote)
In many cases, you will run into conflict because you had changed a line in a file that another teammate added. In such cases, you need to resolve the conflicts manually.

  1. Git Diff

Git Diff is my go-to command when I want to quickly see the difference between my current branch and another branch (usually the branch Im merging into).

Using Git Diff Command

$ git diff
This will show you any uncommitted changes in your local repo.

To compare two branches

$ git diff branch1..branch2
This will show all the file differences between the two branches.

To compare a file from two branches

$ git diff branch1 branch2 ./path/to/file.txt
This command will show a comparison of the changes made to file file.txt across the branches branch1 and branch2.

  1. Git Stash

Git Stash temporarily shelves your work, so you can switch to another branch, work on something else, and then come back to this at a later time.

Its perfect if you need to work on something else and youre midway through a code change, but arent ready to commit the code.

Using Git Stash Save Command

$ git stash save (stash-message)
This will stash your changes with the message you entered. This can be helpful when you want to come back and restore your stash, especially when you have several stashes.

However, this will only stash your tracked files that you added using git add. If you want to include the untracked files as well, run

$ git stash save -u
Using Git Stash List Command

When you want to view all the stashed code, you can view them using this command. Once you stash your code, git will assign a stash id, so you can restore a specific stashed code later.

For example:

$ git stash list
This might show the following

stash@{0}: On master: Stashed with message1
stash@{1}: On master: Stashed with message2
Using Git Stash Apply Command

This will automatically restore and apply the topmost stash in the stack.

$ git stash apply
If you want to restore a specific stash that you want to apply, using the above example, you can simply run git stash apply stash@{1}.

Note: When you use git stash apply, the stashed version will be applied to your current working branch. However, it will not delete the stash from the stack.

Using Git Stash Pop Command

To automatically also delete the stash from the stack, the git stash pop command is used.

If you want to do it for a specific stash in the stack, run git stash pop stash@{0}.

  1. Git Status

When youre feeling a bit lost with whats happened in your repo (yes, it can happen) the Git Status command can tell you all the information youll need to know.

Using Git Status Command

$ git status
This can give you information such as:

Your current branch
Whether your current branch is up to date
If theres anything in the branch that needs to be committed, pushed, or pulled.
If you have any files that are either staged or not staged.
And if you have any files that are created, modified, or deleted.

  1. Git LogWhile git status gave you nearly all the information youd have needed, it wouldnt give you the information about the commit history for the repository.

This is where the git log command comes into the picture.

Using Git Log Command

$ git log
This displays the entire commit history. If your commit history is large, itll show only a portion of it and you can hit [space] to scroll or type q to quit.

If you want to view only the last 3 commit history, you can use the following command: git log -n 3.
To condense the commit history into a single line and view them, run git log --oneline. This is the easiest way to get a high level overview of all the commit history. It might still be a bit too much if youve got a lot of commits.
If you want to view the commit history by a specific author, run git log --author"(author-username)".

  1. Git MergeOnce youre done with development inside your feature branch and tested your code, you can merge your branch with the parent branch. This could be either a develop branch or a master branch depending on the git workflow you follow.

When running a git merge command, you first need to be on the specific branch that you want to merge with your feature branch.

Lets see how to use the git merge command with an example.

Using Git Merge Command

Imagine youre currently in your feature branch called feature1 and youre ready to merge it to the develop branch.

We must first switch to the develop branch using the checkout command.

$ git checkout develop
Before merging, you must make sure that you update your local develop branch. This is important because your teammates mightve merged into the develop branch while you were working on your feature. We do this by running the pull command.

$ git pull
If there are no conflicts while pulling the updates, you can finally merge your feature1 branch into the develop branch.

We do this by using the git merge command followed by the branch name that we want to merge into our current branch.

this is enough i will write more on next blog if i write here it will be overwhelming so thankyou for keeping up with me so lets meet on next blog.


Original Link: https://dev.to/choppalibhargav/github-a-developer-world-36m2

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To