GitHub

GitHub

GitHub, Inc. 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

Difference between pushing and pulling

Pushing

Use git push to push commits made on your local branch to a remote repository.

The git push command takes two arguments:

  • A remote name, for example, origin
  • A branch name, for example, main

For example:

git push  <REMOTENAME> <BRANCHNAME> 

As an example, you usually run git push origin main to push your local changes to your online repository.

By default, and without additional parameters, git push sends all matching branches that have the same names as remote branches.

To push a single tag, you can issue the same command as pushing a branch:

git push  <REMOTENAME> <TAGNAME> 

To push all your tags, you can type the command:

git push  <REMOTENAME> --tags

Pulling

git pull is a convenient shortcut for completing both git fetch and git merge in the same command:

$ git pull remotename branchname
# Grabs online updates and merges them with your local work

Because pull performs a merge on the retrieved changes, you should ensure that your local work is committed before running the pull command. If you run into a merge conflict you cannot resolve, or if you decide to quit the merge, you can use git merge --abort to take the branch back to where it was in before you pulled


Setting up a repository

  1. Create a directory to contain the project.
  2. Go into the new directory.
  3. Type git init .
  4. Write some code.
  5. Type git add to add the files (see the typical use page).
  6. Type git commit .

CLONE

The "clone" command downloads an existing Git repository to your local computer. You will then have a full-blown, local version of that Git repo and can start working on the project. Typically, the "original" repository is located on a remote server, often from a service like GitHub, Bitbucket, or GitLab).

Cloning a repository using the command line

  1. On GitHub, navigate to the main page of the repository.
  2. Above the list of files, click Code.
  3. To clone the repository using HTTPS, under "Clone with HTTPS", click . ...
  4. Open .
  5. Change the current working directory to the location where you want the cloned directory.

Ignoring some files/folders from pushing

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

BRANCH

A branch is a parallel version of a repository. It is contained within the repository, but does not affect the primary or main branch allowing you to work freely without disrupting the "live" version. When you've made the changes you want to make, you can merge your branch back into the main branch to publish your changes.

The developers in the team constantly commit their work into a single, central branch—which is always in a deployment-ready state. In other words, the main branch for the project should only contain tested and quality work, and should never be broken.

So when you want to make changes, you’d create a new branch from the master branch, make your changes in it, and when you’re ready, you’d request your changes to be merged into the master branch.

Here’s a visual example of how working with multiple branches might look like:

No alt text provided for this image

Creating a New Branch From GitHub Website

Navigate to the main page of the GitHub repository for which you want to create a new branch.

You’ll see the name of your current branch in the branch selector dropdown. To see all the branches in the repository, click on [NUMBER Branches]. In my case, you can see that I’m currently on Master branch and I have 2 branches.

No alt text provided for this image

To create a new branch, click on the branch selector dropdown and start typing the name of the new branch in the text box.

By default, this text box checks if there’s an existing branch with the name you just entered.

If not, you’ll be able to create a new branch by selecting “Create Branch”.

This will automatically create a new branch with the Master branch as your base branch.

In the same way we can create as many branches as required, for example

No alt text provided for this image

Merging


Merging another branch into your project branch

  1. In GitHub Desktop, click Current Branch.
  2. Click Choose a branch to merge into BRANCH.
  3. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. ...
  4. Click Push origin to push your local changes to the remote repository.
No alt text provided for this image


If you need to push your changes back to the main branch, use ''git checkout master'' and ''git merge <your branch name>''. This will move all commits on your new branch to the original branch.

In GitBash merging branches to master branch

No alt text provided for this image

This is a common workflow for short-lived topic branches that are used more as an isolated development than an organizational tool for longer-running features.


Now,This command merges the specified branch into the current branch, but always generates a merge commit

No alt text provided for this image



GitHub is fun when you actually make use of it at Organisational level for developing projects, Hope you enjoyed the Blog.

THE END.


要查看或添加评论,请登录

社区洞察

其他会员也浏览了