May 27th, 2023
Git Remote repository

Available git repos

				
					git@129.146.31.88:/home/git/git-repo/spring-jwt.git
git@129.146.31.88:/home/git/git-repo/ms1.git
git@129.146.31.88:/home/git/git-repo/ms2.git
git@129.146.31.88:/home/git/git-repo/spring-microservices-01
git@129.146.31.88:/home/git/git-repo/kubernetes.git
				
			
				
					#=========================
#   ON CLIENT
#=========================

# Go to ~/.ssh and generate a SSH key pair using ssh-keygen
ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}

# Go to this file
vim .ssh/config
# add these
Host *.github.com
  IdentityFile ~/.ssh/github.com

#=========================
#   ON SERVER
#=========================
# Add the public key on server
# go to this file
vim ~/.ssh/authorized_keys
# - OR
vim ~/.ssh/known_hosts
# oraclegitpassword
# add the public key {ssh-key-name}

/**
* -----------------------------
* Create repo on live server
* -----------------------------
*/
# Login with git user, and create the repo
su git
git/oraclegitpassword

# create git repo
git init --bare ~/project.git

/**
* -----------------------------
* Add existing project to 
* live git server
* -----------------------------
*/
# Go to existing project
git init .

# complete the remaining git commands
git add .
git commit -m "msg"
git push --set-upstream origin main

# connect git on live server
git remote add origin ssh://git@129.146.31.88:/home/git/git-repo/spring-microservices-01
pwd:medhansh


# connect git on local network
git remote add origin ssh://soundarya@192.168.1.6:/home/soundarya/spring-durgesh/Springboot-LSF.git
git branch --set-upstream-to=origin/master

# change origin url of git
git remote set-url origin new.git.url/here
				
			

Update the Remote branch on Git. Before proceeding make sure you are on that current branch which needs to be renamed to new branch name.

				
					# 1. Checkout to the branch which requires name change
git checkout <branch_name>

# 2. Rename local <branch_name> to <new_branch_name>
git branch -m <new_branch_name>

# 3. Delete the branch
git push origin --delete <branch_name>

# 4. Push the new branch name
git push origin -u <new_branch_name>
    
# 5. Update origin url
git remote set-url origin git://new.url.here

# 6. Delete origin url
git remote remove origin
				
			

Delete remote branch of Git

https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely

 

If you want more detailed explanations of the following commands, then see the long answers in the next section.

Deleting a remote branch

git push origin --delete <branch>  # Git version 1.7.0 or newer
git push origin -d <branch>        # Shorter version (Git 1.7.0 or newer)
git push origin :<branch>          # Git versions older than 1.7.0

Deleting a local branch

git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force-delete un-merged branches

Deleting a local remote-tracking branch

git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter

git fetch <remote> --prune # Delete multiple obsolete remote-tracking branches
git fetch <remote> -p      # Shorter

The long answer: there are three different branches to delete!

When you’re dealing with deleting branches both locally and remotely, keep in mind that there are three different branches involved:

  1. The local branch X.
  2. The remote origin branch X.
  3. The local remote-tracking branch origin/X that tracks the remote branch X.

Visualization of three branches

The original poster used:

git branch -rd origin/bugfix

Which only deleted his local remote-tracking branch origin/bugfix, and not the actual remote branch bugfix on origin.

Diagram 2

To delete that actual remote branch, you need

git push origin --delete bugfix

Diagram 3

Additional details

The following sections describe additional details to consider when deleting your remote and remote-tracking branches.

Pushing to delete remote branches also removes remote-tracking branches

Note that deleting the remote branch X from the command line using a git push will also remove the local remote-tracking branch origin/X, so it is not necessary to prune the obsolete remote-tracking branch with git fetch --prune or git fetch -p. However, it wouldn’t hurt if you did it anyway.

You can verify that the remote-tracking branch origin/X was also deleted by running the following:

# View just remote-tracking branches
git branch --remotes
git branch -r

# View both strictly local as well as remote-tracking branches
git branch --all
git branch -a

Pruning the obsolete local remote-tracking branch origin/X

If you didn’t delete your remote branch X from the command line (like above), then your local repository will still contain (a now obsolete) remote-tracking branch origin/X. This can happen if you deleted a remote branch directly through GitHub’s web interface, for example.

A typical way to remove these obsolete remote-tracking branches (since Git version 1.6.6) is to simply run git fetch with the --prune or shorter -pNote that this removes all obsolete local remote-tracking branches for any remote branches that no longer exist on the remote:

git fetch origin --prune
git fetch origin -p # Shorter

Here is the relevant quote from the 1.6.6 release notes (emphasis mine):

“git fetch” learned --all and --multiple options, to run fetch from many repositories, and --prune option to remove remote tracking branches that went stale. These make “git remote update” and “git remote prune” less necessary (there is no plan to remove “remote update” nor “remote prune”, though).

Alternative to above automatic pruning for obsolete remote-tracking branches

Alternatively, instead of pruning your obsolete local remote-tracking branches through git fetch -pyou can avoid making the extra network operation by just manually removing the branch(es) with the --remotes or -r flags:

git branch --delete --remotes origin/X
git branch -dr origin/X # Shorter
 

Leave a Reply

Your email address will not be published. Required fields are marked *