Showing posts with label git admin. Show all posts
Showing posts with label git admin. Show all posts

Sunday, March 22, 2026

Git Fork vs Git Branch Explained for Beginners and Developers

If you are learning Git or working in a development team, you will often hear the terms fork and branch. Understanding the difference between them is essential for efficient collaboration and version control.

In this guide, we will explain Git fork vs Git branch in a simple and practical way with examples and use cases.

What is a Git Branch?

A Git branch is a separate line of development within the same repository. It allows developers to work on features, bug fixes, or experiments without affecting the main codebase.

Git Branch Example

git checkout -b feature/login

This command creates a new branch called feature/login and switches to it.

Git Branch Workflow

  1. Create a branch
  2. Make code changes
  3. Commit changes
  4. Merge changes into main branch
git checkout main
git merge feature/login

When to Use Git Branch

  • Feature development
  • Bug fixing
  • Code experimentation
  • Team collaboration within the same repository

What is a Git Fork?

A Git fork is a copy of an existing repository into your own GitHub account. It allows you to modify the code without affecting the original project.

Git Fork Example

After forking a repository, you clone it locally:

git clone https://github.com/your-username/project.git

Git Fork Workflow

  1. Fork the repository from GitHub
  2. Clone the forked repository
  3. Create a branch
  4. Make changes
  5. Push changes to your fork
  6. Create a Pull Request to the original repository

When to Use Git Fork

  • Contributing to open source projects
  • Working without direct repository access
  • Maintaining your own version of a project

Difference Between Git Fork and Git Branch

Feature Git Branch Git Fork
Definition Separate line of development Copy of a repository
Location Inside same repository Different repository (your account)
Access Required Yes No
Usage Internal team work External contributions
Collaboration Direct merge Pull request required

Real World Examples

Using Git Branch in a Team

Developers create branches for features and merge them into the main branch.

main -> feature/payment -> merge

Using Git Fork for Open Source

Developers fork a repository, make changes, and submit a pull request.

original repo -> fork -> branch -> pull request

Best Practices for Git Workflow

  • Always create a new branch for each feature or fix
  • Use clear and meaningful branch names
  • Keep your fork updated with the original repository
  • Follow a consistent Git workflow
git remote add upstream https://github.com/original/repo.git
git fetch upstream
git merge upstream/main

Conclusion

Understanding the difference between Git fork and Git branch is important for modern software development.

Use branches for daily development within your team and forks when contributing to external repositories.

This approach helps maintain clean code, better collaboration, and efficient version control.

Tuesday, November 26, 2024

How to Copy Git Repository Without History

There are several methods to do this using git clone, git push or using git archive. But I personally prefer the one using git clone.

Objective is to copy repo 1 which is source repo to a new Repo which is NewRemote repo with out commit history.

Precautions before you proceed with this:

  1. Ensure you have write access to the repository.
  2. Backup any important local changes before proceeding.
  3. This will permanently remove the old commit history.
  4. Collaborators will need to re-clone the repository.

Here are step by step git examples for this specific repo

# 1. Clone the source repository
git clone https://github.com/inagasai/SourceRepo.App.git

# 2. Enter the cloned repository directory
cd vGlence.App

# 3. Verify current branches
git branch -a

# 4. Checkout master branch
git checkout master

# 5. Create a new branch without history
git checkout --orphan clean-main

# 6. Add all files to the new branch
git add .

# 7. Commit the files with a new initial commit
git commit -m "Initial commit - reset repository history"

# 8. Delete the old main branch (if it exists)
git branch -D main 2>/dev/null

# 9. Rename current branch to main
git branch -m main

# 10. Remove the original remote
git remote remove origin

# 11. Add the original repository as a new remote
git remote add origin https://github.com/inagasai/NewRemote.App.git

# 12. Force push to overwrite the remote repository
git push -f origin main
  

Detailed Breakdown of the outcome:

  1. This process creates a new branch with no commit history.
  2. It adds all existing files to a new initial commit.
  3. Force pushes to overwrite the remote repository.
  4. Removes all previous commit history.

Hope this helps.

Tuesday, June 27, 2023

Git Cheat Sheet: Essential Commands for Version Control Mastery

Git is a powerful and widely used version control system that enables developers to efficiently manage their codebase and collaborate on projects. However, mastering Git can be a daunting task, especially for beginners. To ease your learning curve, we've prepared a comprehensive Git cheat sheet that includes the most essential commands you'll need to navigate through Git's functionalities. Whether you're a novice or an experienced developer, this cheat sheet will serve as a handy reference to help you streamline your version control workflow.

Git Configuration:

  • git config --global user.name "[name]": Set your username for Git.
  • git config --global user.email "[email address]" : Set your email address for Git.
  • git config --global color.ui auto: Enable colorful output in Git.

Repository Creation and Cloning:

  • git init: Create a new Git repository in the current directory.
  • git clone [repository URL]: Clone an existing repository to your local machine.

Basic Workflow:

  • git add [file]: Add a file to the staging area.
  • git commit -m "[commit message]": Commit your changes with a descriptive message.
  • git status: Check the status of your repository.
  • git log: View the commit history.
  • git diff: Show the differences between your working directory and the last commit.

Branching and Merging:

  • git branch: List all branches in the repository.
  • git branch [branch name]: Create a new branch.
  • git checkout [branch name]: Switch to a different branch.
  • git merge [branch name]: Merge a branch into the current branch.
  • git stash: Temporarily save changes that you don't want to commit yet.

Remote Repositories:

  • git remote add [remote name] [remote URL]: Add a remote repository.
  • git push [remote name] [branch name]: Push your local changes to a remote repository.
  • git pull [remote name] [branch name]: Fetch changes from a remote repository and merge them into your local branch.

Collaboration:

  • git branch -r: List remote branches.
  • git fetch: Download objects and refs from a remote repository.
  • git branch -d [branch name]: Delete a branch.
  • git clone --branch [branch name] [repository URL]: Clone a specific branch of a repository.

Undoing Changes:

  • git reset [commit]: Un stage commits, preserving changes.
  • git revert [commit]: Create a new commit that undoes changes from a previous commit.
  • git checkout -- [file]: Discard changes in a specific file.

This Git cheat sheet provides you with a quick reference to the most commonly used commands for version control. By familiarizing yourself with these commands, you'll be able to navigate Git's functionalities with ease, collaborate effectively, and maintain a clean and organized codebase. Remember, practice makes perfect, so don't hesitate to experiment and explore additional features and options available in Git. Happy coding!

Please consider this cheat sheet as a starting point for your Git journey, and continue to expand your knowledge by exploring additional resources and documentation.

Sunday, June 13, 2021

Git: How to set Git User Name and User email Globally & repository specific

Usually when we install Git, we typically configure your global username and email address after installing Git. However, you can do so now if you missed that step or want to make changes. After you set your global configuration, repository-specific configuration is optional.

Git configuration works the same across Windows, macOS, and Linux.

To set your global username/email configuration:

Open the command line.

-- set user name
$ git config --global user.name "First Name Last Name"
-- set user email
$ git config --global user.email "useremail@gmail.com"

To set repository-specific username/email configuration:

From the command line, change into the repository directory.

--Set your username
$ git config user.name "FIRST_NAME LAST_NAME"

--Set your email address
$ git config user.email "useremail@gmail.com"

--Verify your configuration by displaying your configuration file
$ cat .git/config

Hope this helps!