Getting Git Code Management

I am now the code manager for the public repository of a project that takes pull requests from several active forks and has tagged releases. The problem is, that I've not found any single resource that covers advanced code management using Git. My local repository has multiple upstream sources that I synchronize. All are hosted at github.com.
This post is going to be a collection of little Git recipes. Many of them are collected from somewhere else, but others are more specific to the code management processes

Configure git for certificate-based credentials for multiple logins

Generate certificate

I was able to get this working by following the instructions here. However, I also needed to add some commands to my "~/.basrc" file to provide my SSH credentials to the git/bash shell window. Each ssh-add command adds one certificate to the identity store.

#! /bin/bash 
eval `ssh-agent -s` 
ssh-add ~/.ssh/github_rsa
ssh-add ~/.ssh/github_admin_rsa

Make the local copy an exact copy of a named remote and branch

git reset remote/branch --hard
git clean -fd

Update the local copy to have all the changes in a named remote and branch

git pull -X ours --rebase remote branch

Merge changes into the local copy from named remote and branch

git merge remote/branch

Merge a remote pull request locally (after a clean)

git fetch remote 
git merge remote/pr/123

Push to a remote

git push remote branch

Create a new local branch

git checkout -b newBranch

Copy a remote branch locally

git checkout -b localBranch remote/branch

Apply a tag or overwrite an existing one.

A tag works like a branch in many respects, so you can do a "git checkout tagName" to get the tagged version.
git tag tagName -f

Update a tag with a cherry-picked commit

git checkout my_tag
git cherry-pick commit_123
git tag -f my_tag
git push repository --tags

Master and upstream repositories

For these commands, if you have supplied the credentials using the certificate method listed above, the URL will include the alias name contained in the "~/.ssh/config" file. I.e. use git@github-user:GithubUser/repo.git instead of "https://github.com/GithubUser/repo.git". Your config file should look something like this:

#~/.ssh/config
ForwardAgent yes
Host github-user
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_user_rsa
Host github-admin
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_admin_rsa

and your "git remote -v" command should yield something like this:

user git@github-user:Organization/repository.git (fetch)
user git@github-user:Organization/repository.git (push)
admin git@github-admin:Organization/repository.git (fetch)
admin git@github-admin:Organization/repository.git (push)

by using the "user" and "admin" repository aliases, you work with the same repository from different accounts!

Clone a remote repository locally

git clone https://github.com/.../somerepo.git

Add a new upstream repository to a local

git remote add upstreamBranchName https://github.com/.../repo.git

Comments

Popular posts from this blog

Database Projects, SQL Unit Tests, and TeamCity

Building nice XML from SQL Server Tables

Brent: Programmer. Gamer. Cheapskate. All around good guy.