# From Local to Global: Mastering the Push from Your Workspace to Your GitHub Repository

As a software developer, pushing code from your local folder to a GitHub remote repository is a common task you'll encounter daily. Here’s a detailed guide on how to do this using the Git command line interface (CLI), as demonstrated

1. Initialize Your Local Git Repository
    
    First, you need to have a local Git repository. Navigate to your project directory and initialize Git:
    
    ```plaintext
    cd /path/to/your/project
    git init
    ```
    
2. #### Add a Remote Repository
    
    Before pushing your code, you must specify the remote repository's URL. This is done using the `git remote add` command:
    
    here is how remote\_repo\_url looks like
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1711543126861/190fd73c-e8fa-4c80-b354-0daaf821836a.png align="center")
    
    ```plaintext
    git remote add origin your_remote_repo_url
    ```
    
3. However, if you encounter an error saying "remote origin already exists," it means a remote repository is already configured. You can check existing remotes with:
    
    ```plaintext
    git remote -v
    ```
    
    #### Remove the Existing Remote (If Necessary)
    
    If you need to change the remote URL or it was incorrectly set, you can remove it:
    
    ```plaintext
    git remote remove origin
    ```
    
4. Then, add the correct remote repository:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1711543156063/af3cc344-5dd8-482b-b9d3-90ce870e830c.png align="center")
    
    ```plaintext
    git remote add origin https://github.com/your_username/your_repository
    ```
    
5. Verify the remote configuration to ensure accuracy:
    
    ```plaintext
    git remote -v
    ```
    
6. #### Stage and Commit Your Changes
    
    Before pushing, stage your changes with `git add` and then commit them:
    
    ```plaintext
    git add .
    git commit -m "Your commit message"
    ```
    
    During this process, you may encounter warnings about line endings (LF will be replaced by CRLF), which are common when working across different operating systems.
    
7. #### Push Your Changes to the Remote Repository
    
    Finally, push your changes to the remote repository:
    
    ```plaintext
    git push origin main
    ```
    
8. #### Verify Your Push
    
    After pushing, you should see output indicating the successful transfer of commits to the remote repository. You can also verify this by checking your GitHub repository in a web browser.
    

### **Conclusion**

Pushing code to a remote repository like GitHub using Git CLI is a straightforward process that involves initializing a repository, managing remote connections, staging, committing, and finally pushing changes. Always ensure your remote URL is correctly set and that your local changes are properly committed before pushing. This workflow is essential for version control and collaboration in software development.

Go and have FUN ! 😎  
Author✒️:@[Pranabesh Pratihar](@Pranabesh) 🫡
