Git : A basic understanding for every Dev - Part III

Git : A basic understanding for every Dev - Part III

ยท

3 min read

In this section, we will take a look at initializing remote repositories

Initialize Remote Repositories

We can push code to the remote repositories that are hosted somewhere else and get this code on our local machines by pulling this information.

  • There are several platforms where we can host our remote repositories. The most commonly used ones are the ones below

    1. Github

    2. Gitlab

    3. Bitbucket

  • Once we initialize a repository on these platforms, we will get access to something called connection string.

  • A connection string is a URL that we can use to let git know where the remote repository is located.

  • To add a remote repository to a local project

      $ git add remote origin <connection URL>
    
  • To list all remote repositories

      $ git remote -v
    

Pushing to remote repositories

In this section, we will take a look at pushing to remote repositories

To keep our local and remote repo in sync, we have to push the data from the local repo to the remote repo

  • To push data from the local to the remote repo

      $ git push origin master
    

Cloning Remote Repositories

In this section, we will take a look at cloning remote repositories

We can clone the remote repository on our local machines

  • To clone the remote repo with an ssh link

      $ git clone <ssh-link-goes-here>
    
      $ git clone git@github.com:account/remote-repo.git
    
  • To check the history of the project

      $ cd remote-repo
      $ git log
    

Pull Requests

In this section, we will take a look at Pull requests

To push the latest changes to the GitHub newdemo branch

$ git push origin newdemo

To push changes from newdemo to master we have to open something called Pull Request

Merge Conflicts

In this section, we will take a look at merge conflicts

Remove the lines that we don't wanna keep to resolve the conflicts and save the file.

* Add the changes to git again

$ git add demofile2.txt

Fork

How do you create a pull request if you are not part of a git project?

  • One way to contribute to such projects is to fork the main project.

  • After forking the project you can add your changes to a branch on the forked copy and send a pull request to the original project to merge your changes.

Want to learn and explore more about git? Then do checkout the Git : A basic understanding for every Dev - Part IV

Hop into the blog section for a more interesting and detailed overview of Software development and other stuff. ๐Ÿ˜Š

Did you find this article valuable?

Support #DevOps Daily-Dose by becoming a sponsor. Any amount is appreciated!

ย