Config option for git-tfs checkin to use --no-merge by default - git-tfs

Is there an option to add something to git-tfs config, so the checkin (and checkintool) command uses --no-merge flag by default.
I want to use
git tfs checkin
instead of
git tfs checkin --no-merge

I don't think you can, but did you consider making an alias and use that for checking in?
git config --global alias.tc "tfs checkin --no-merge"
git tc

Related

Push current code to existing GitHub repository

I have several Visual Studio solutions that have both a local repository and one on GitHub. I've already made many changes and successfully pushed those changes to GitHub.
But now Visual Studio has forgotten that one of my local repositories is associated with a GitHub repository and I can't seem to figure out how to reconnect it. In fact, it no longer lists that repository in my list of GitHub repositories.
In the image below, you can see I have a local repository called Toxic, but that repository does not appear in the list of GitHub repositories. If I try publishing the Toxic project to GitHub, it just tells me the repository already exists.
How the heck can I get all of my existing Github repositories to show up in the top section shown above so I can push my latest changes?
it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.
Try fist:
installing Git for Windows (command-line)
cloning your remote repo in a new folder
adding your existing repository as a remote
fetching and see if you can cherry-pick your commits
That is:
git clone https://github.com/<user>/<repo> newFolder
cd newFolder
git remote add old ../path/to/old/local/repo
git fetch old
git log old/master
git cherry-pick old-sha1..old/master
(with old-sha1 being the first commit you want back)
Then add the newFolder in your Visual Studio workspace, and see if everything works (do a modification, add, commit and push)
Unless I'm missing something, it appears the only option is to clone the GitHub repository locally, copy my modified files over the newly created repository, and then check in my changes.
Of course, I lose all my comments and iterations since the last check in to GitHub. And care had to be taken not to delete the .git folder, and to copy over all changed file and delete any that had been removed. Seems like there should be an easier way but this certainly did the trick.
I'm no git expert, but I think I might be able to help, if I'm not too late.
Run:
git remote -v
This should print something in the form of:
origin <remote_repo_url> (fetch)
origin <remote_repo_url> (push)
If you only see:
origin (fetch)
origin (push)
try running:
git remote set-url origin <remote_repo_url>
If you get no output then run:
git remote add origin <remote_repo_url>
And then try
git push -u origin
The -u or --set-upstream flag will set origin as the default repo for your branches.

how to make git checkout <tab> show only the branches I have locally

When I want to check a branch to checkout to and I don't remember the exact name, I can't use Tab-completion, as the pool it uses is the branch pool of remote.
How can I make the Tab only look at the git branch pool (i.e. only choose from the local branches I created / already checkedout)
One way is to modify the standard code completion script for git checkout, example (& credit) below:
https://gist.github.com/mmrko/b3ec6da9bea172cdb6bd83bdf95ee817
If i understand your problem you can first run
git branch
if the branch is locally.
Else you can
git branch --all
if the branch is on repository and you didn't checkout it yet.
Then you can
git checkout <branchName>

revert git back initial condition

I was trying to add a repository to my xcode project, but instead of adding my project files to the repository, git removed my entire project. I think I can use 'git revert' option to revert the changes, but how do I know where to revert to?
Get the list of commits using
git log this will list out all the commits with its hash, to revert the commit use
git revert (part of the hash)
for example if the commit hash is adghgd356484fghfbht76, do
git revert adghgd3564
If you have not pushed your changes to remote, you can run git reset --hard which will undo all your local changes and you will loose those changes from the history as well

Using git-tfs fetch to get latest causes a merge conflict

I have an issue attempting to pull my latest changes from TFS and adding them to a BitBucket repo. I have successfully pushed my branches into BitBucket, but when I attempt to get any new checkins from TFS I always get a merge conflict.
Steps:
git tfs clone http://TFS-ADDRESS/Collection $/Project/Name/Branch
git tfs init-branch $/Project/Name/NewBranch NewBranchName
git push -u origin --all
At this point my BitBukcet repo has all my files and history from TFS.
I then did a checking into me $/Project/Name/NewBranch on TFS.
Now I want to get the latest changesets from TFS and add/commit them into the BitBucket repository Note: At this point, no other branch in TFS or BitBucket has changed. The only change is my single check-in into TFS
When I do the following on my NewBranch, I get a merge conflict:
git tfs pull
Auto-merging Source/build.version
CONFLICT (content): Merge conflict in Source/build.version
As far as I can tell, it is trying to merge changes from my "master" to my "NewBranch", even though NewBranch is the latest code.
The ptfs pull command is pulling the last checgeset down, but then tries to do the merge. If I use
git tfs fetch --all
I see the changeset listed, but I cannot commit/push it to the BitBucket repository. I cannot find a reference online to say what I am doing wrong, or what steps I need to take (I am new to Git). Can anyone help?
I eventually want to automate this so any check-ins in TFS can be fetched and added to the BitBucket repository (until we eventually move all developers to BitBucket)
Thanks
EDIT
I am trying to take changes from TFS to BitBucket. Nothing is getting added to TFS from BitBucket.
All work is done on a branch (see below). Users are working in TFS. Users commit their changes there. NOTE: No-one is making edits to the BitBucket repo. It is a replica of TFS.
Once a day, I want to pull the latest changesets for each TFS branch down to my local git folder and them push them into BitBucket. The "git tfs fetch" retrieves the changesets:
D:\development\workspaces\git\anothertry>git tfs fetch --all
C83419 = 3abdaedf571369dce15f74a52697d86069f87d6d
but "git status" tells me there is nothing to commit
D:\development\workspaces\git\anothertry>git status
# On branch Feature
nothing to commit, working directory clean
And when I try to push this changeset into BitBucket, git tells me there is nothing to commit.
Branches
Master---o---------------o----o--o-o--o-------
\ / / / / /
Feature-----o----o--o-o--o
I seem to have found the answer after using Git Extensions.
It seems I need to do a fetch
git tfs fetch --all
This will get me all changesets from TFS for my trunk and any branches I have mapped (init-branch)
D:\development\workspaces\git\anothertry>git tfs fetch --all
C83454 = f65ba8d0cc7b40f42148ba2c06d0da8b7e968c4d
C83455 = 6c25feb6e74a09d0d3d84344002e7546044900ab
C83459 = 91c4450d702d5a97e862aedd7ad1b5af3ff2c375
C83460 = 5cacaba5bfe4197c1bf9fab498f51c1ba435e6ea
Next I need to perform a merge
git merge <guid>
NOTE: The is for the latest changeset (in this case 5cacaba...)
Updating 6c25feb..5cacaba
Fast-forward
Source/Common/w32threads.h | 1238 ++---
Source/xxxxxxx_Service/ServerAgent.cpp | 3638 ++++++-------
Source/xxxxxxx_Service/ServerAgent.h | 449 +-
Source/xxxxxxx_Service/User.cpp | 9073 ++++++++++++++++----------------
Source/xxxxxxx_Service/User.h | 647 +--
Source/build.version | 2 +-
6 files changed, 7562 insertions(+), 7485 deletions(-)
And, finally, push my changes to BitBucket
git push --all
So, it seems I was missing the git merge call and the parameters to pass to it.
Cheers
I don't exactly understand what you do bad but there is somethings that you should now in using git-tfs...
Working with a TFS branch
I see that you created a branch (step 2) and commit in that branch.
When you have checkouted your branch 'NewBranchName', you should checkin with the command :
git tfs rcheckin -i NewBranchName
and pull modifications with :
git tfs pull -i NewBranchName
or (with rebase)
git tfs pull -r -i NewBranchName
If you don't specify the -i option with the name of the TFS remote, you will check in your commit in the main branch (here, $/Project/Name/Branch ) :(
Checkin your commits on TFS
I give you above the command to check in your commits. But you should know that, for some reasons, when you check in a git commit in TFS, a new changeset in TFS is created (that's what we want ;) ) and after a new git commit is created. It's nearly the same that the original but with some informations (that you can see in the git comment).
Due to this fact, depending on what you do (and I don't exactly understand what), you could have problems because git try to merge commit with exactly the same modifications at the same place, so fail to merge automaticaly.
In fact, I think there is something wrong in your workflow because you shouldn't encounter this problem. Try to find the problem in your workflow.
I hope it will help.
Feel free to see the git-tfs wiki : https://github.com/git-tfs/git-tfs/wiki
I hope there is quite useful informations (partly did it, with love ;) )
PS : To help you better, can you tell me which command you use to checkin your commits?
checkin, checkintoo, rcheckin? rcheckin is heavily advised!
What I do to automate your workflow :
(here 'bitbucket' is the supposed name of your remote bitbucket repository)
=> in your master branch :
//Do your job & commit with git & ...
//rebase your work on TFS work
git tfs pull -r
//rcheckin with git-tfs
git tfs rcheckin
//commit in bitbucket repo
git push bitbucket master
=> in your 'NewBranchName' branch :
//Do your job & commit with git & ...
//rebase your work on TFS work
git tfs pull -r -i NewBranchName
//rcheckin with git-tfs
git tfs rcheckin -i NewBranchName
//commit in bitbucket repo
git push bitbucket NewBranchName
PS2 : Perhaps, you should have to stash your modifications if you have uncommited changes in your working directory before doing pull -r and rcheckin...
EDIT : You edit, I edit ;)
Before, I suppose that you have defined a remote for your bitbucket repository :
git remote add bitbucket https://bitbucket.org/yout_login/your_project.git
You have just to :
//checkout your branch
git checkout NewBranchName
//fetch the TFS changesets and merge your branch into
git tfs pull -r -i NewBranchName
//push your commit on bitbucket
git push bitbucket NewBranchName
And to explain a little what you are doing (and not understand totally :( )...
With "git tfs fetch --all", you are fetching the TFS changeset of all the branches but not merging (or rebasing) with your local branch. So they doesn't appear in your local branch.
You could see the DAG with the command to better understand :
git log --oneline --graph --decorate
The 'git tfs pull' given above merge the fetched commit with your branch so that will be good!
"git status" tells me there is nothing to commit
This command show you the files that are modified in the working directory. So, that's normal that you see no changes. That does say that your commit was not pulled!
And when I try to push this changeset into BitBucket, git tells me there is nothing to commit.
You should have! Are you sure to have define your remote toward your bitbucket repository? (see above)
Which command you use? What git tell you?
The git tfs fetch command doesn't update your local git repository, that's why you should do git merge after that.
To do the same in one command simply do pull from TFS remotes
git tfs pull -r
This should update local git repository with all new updates from TFS server
At this point you just need to push updates to git server:
git push -u origin --all

phpstorm git pull --rebase

In phpstorm how do you do a git pull --rebase? I can't seem to find an option to do it. I would like this to be the default behavior as we are all working off the same branch.
I am doing the pull by Version Control > Git > Pull Changes....
Just use the Version Control -> Update Project action.
There you may choose the way of update: via merge (git pull) or via rebase (git pull --rebase) or via the default way for the current branch (it is merge by default).
The action also has more capabilities than Pull: it stashes/slelves your uncommitted changes if you have them, and restores them after update.

Resources