git alias to merge and delete branch - alias

I'd like a git alias to merge then delete a single local branch. The question How to alias in git delete merged branches addresses how to remove all merged branches; I'm essentially looking to keep my local repository clean as I go.

mnd = "!f() { git merge --no-ff ${1} && git branch -d ${1}; }; f"

Related

Add git submodule using a specific commit number

I'm using git submodule commands to add this FSM repo in my project. I want to checkout a specific release commit. By default the master branch is checked out.
After adding the git repo, when I run
$ git submodule
It gives
d1b66d66cfa95f238a7498465908a262f4b2326a directory_path/fsmlite
The commit number here belongs to a master branch commit. How can I checkout another commit instead, using its commit number?
There might be some other way to do this, but I got the desired commit by
$ cd directory_path/fsmlite
$ git checkout v0.7.1 (this is the branch I wanted to point to)
$ git submodule update
$ cd parent_dir
$ git submodule
+de19ea0a71cb6082fe9311694a27e8f0cc2f972a directory_path/fsmlite (v0.7.1)
which is the specific commit number I wanted

Git: mark two commits on two branches as same though history of commits on the two is different

I have a dev branch and a master branch.
We make development on dev branch till the release date.
On release day, we rebase all the changes on dev branch "commit-by-commit" to master branch and merge them.
This way we retain the history of commits on master branch as well.
In the past, (PROBABLE REASON) once I forgot to do this commit-by-commit and pushed several commits (say A,B,C) on dev as a single commit to master(A').
Now, everytime I do the said activity in para1, it finds A' as differing and tries to rebase corresponding commits A,B,C to master.
I wish to overcome this by indicating to git
- that repo content pointed by C on dev branch is same as that pointed by A' on master. OR
- that repo content pointed by J on dev branch is same as that pointed by J on master.
With this I hope the tool to pick only new commits.
Is there a way?
dev : /A-B-C =D-E-F=G-H-I-J
master: Z-Y- A'=D-E-F=G-H-I-J
= indicates a merge from dev to master branch for release
/ indicates dev being branched out
git checkout dev
git checkout -b temp-dev [SHA for C]
git checkout master
git checkout -b temp-master [SHA for Y]
git rebase temp-dev
git branch -D master
git branch -D temp-dev
git branch -m temp-master master
git tag [your previous release]
... do the same for F ...
git rebase dev
git tag [your new release]
If I understand you correctly, something like this, maybe?

how to get all branchs from repository?

I'm a new user with git, and I use gitBash.
When I execute $git clone http:..../name.git, the master branch of name is downloading. But when I execute $git branch -a I just see the master branch, no others.
But I have some others branchs... Why I can't see all branches ? How do that ?
thx.
git branch -a only displays local branches you have already checked out.
You want to use git branch -r (where -r stands for remote). This should list all the remote branches available (I can't test this right now, but I'm fairly certain it works).

Create a svn branch from git when directory structure differs

I created a local git copy of an svn repo with the following commands:
$ git svn init svn://host/path/to/repo/PROJECT/trunk workingcopy
$ cd workingcopy
$ git svn fetch
Now I'm trying to create an svn branch without success:
$ git svn branch -n mybranch -m "Branch for my things"
Multiple branch paths defined for Subversion repository.
You must specify where you want to create the branch with the --destination argument
In .git/config I do not have any entries under [svn-remote "svn"] as suggested in this answer. I tried adding branches = branches/*:refs/* but this tries to create the branch under the trunk:
Copying svn://host/path/to/repo/PROJECT/trunk at r6684 to svn://host/path/to/repo/PROJECT/trunk/branches/mybranch
What do I need to do to create a branch in the correct location?
Okay, so I changed .git/config from:
[svn-remote "svn"]
url = svn://host/path/to/repo/PROJECT/trunk
fetch = trunk:refs/remotes/git-svn
to:
[svn-remote "svn"]
url = svn://host/path/to/repo/PROJECT
fetch = trunk:refs/remotes/git-svn
branches = branches/*:refs/remotes/*
This worked, but I ran into problems trying to access the branch from a git repo on another machine. In the end, I pushed my changes to svn, then deleted my local git repo and cloned it properly this time:
$ git svn clone --standard-layout --prefix=svn/ svn://host/path/to/repo/PROJECT

How do I merge a git tag onto a branch

I'm trying to find the syntax for merging a tagged commit onto another branch. I'm guessing that it's straight forward but my feeble search attempts aren't finding it.
You mean this?
git checkout destination_branch
git merge tag_name
Remember before you merge you need to update the tag, it's quite different from branches (git pull origin tag_name won't update your local tags). Thus, you need the following command:
git fetch --tags origin
Then you can perform git merge tag_name to merge the tag onto a branch.
Just complementing the answer.
Merging the last tag on a branch:
git checkout my-branch
git merge $(git describe --tags $(git rev-list --tags --max-count=1))
Inspired by https://gist.github.com/rponte/fdc0724dd984088606b0
This is the only comprehensive and reliable way I've found to do this.
Assume you want to merge "tag_1.0" into "mybranch".
$git checkout tag_1.0 (will create a headless branch)
$git branch -D tagbranch (make sure this branch doesn't already exist locally)
$git checkout -b tagbranch
$git merge -s ours mybranch
$git commit -am "updated mybranch with tag_1.0"
$git checkout mybranch
$git merge tagbranch
I'm late to the game here, but another approach could be:
1) create a branch from the tag ($ git checkout -b [new branch name] [tag name])
2) create a pull-request to merge with your new branch into the destination branch
With modern versions merge will autodetect the tags as follows
git checkout <my-branch>
git merge tags/<my-tag>