Tag: git branch

Why does `git checkout <branch> <file>` stage the change?

If I start from a clean working tree and run git checkout <branch> <file>, where <branch> has a different version of this file, I end up with a staged rather than an unstaged change. What’s the reason for this? Is this just for consistency with other commands like git mv, which you would expect to […]

Git – switching between branches in the middle of work

For various reasons (code review mostly) I need to switch from current development branch to other branches quite often. Currently, I use either ‘git stash‘ to shelve the uncommitted changes, checkout other branch, then switch back and do ‘git stash apply’ However, sometimes I’d have some newly added files there, which are not tracked. Unfortunately, […]

what happens if I stash code in one branch and change to another branch?

I have some code that i want to commit into another branch, however i did the changes before create the branch, so now I’m in master and I want to stash the code, create a local branch, checkout it, and then stash the code into that new branch so i can commit within it. Would […]

Merge branch 'X' of URL into X

When I and my colleague work on the same git branch, each of us sees a strange commit with message “Merge branch ‘X’ of URL into X” where X – the same branch. after pull has been performed (and new changes came from remote). I said “strange” because I previously work with SVN, and this […]

how to get all branches of my forked git repo

I have cloned, pulled and fetched my remote git repo at BitBucket. But I could only get the master branch. My repo at BitBucket has 4 branches: master fix/cleanup etc/schema_note feature/sampledata I have found the two questions this and that. I followed some of the instructions in those questions. When I tried git branch -a, […]

Stop new branch from getting old commit history in Git

I had this structure in Git develop C – D – E / master A – B Then, I added a new branch from develop with: git checkout -b new_branch develop This is what i got new_branch C – D – E – F – G / develop C – D – E It branched […]

Git: should merged branch be always deleted?

I have a question related to git merge workflow. When we merge one branch to another, AFAIK two things may happen: either a single commit would be created on the destination branch (in non fast-forward case) or commits from the merged branch will be applied “on top of” commits on the destination branch. I am […]

JGit create new local branch and push to remote (branch does not exist on remote)

I’m working on an ANT task that calls some java that uses JGit to create a new branch on a git repository and push it to remote. I’m using JGit 2.1.0. Here’s the code: CreateBranchCommand bcc; CheckoutCommand checkout; Git git; try { Repository repo = new FileRepositoryBuilder().readEnvironment().findGitDir(src).build(); git = new Git(repo); bcc = git.branchCreate(); checkout […]

Why “git checkout master” didn't revert file content back to previously?

Say, if the file foo is committed already, having the content of just a simple line now a git checkout -b issue57 is done to create a branch and switch to it (say, that issue57 branch is to last 2 days for development), and a line footer added is added to the file for now, […]

git buggy modified files when changing branches

I have the craziest bug going on with my repo I don’t know what to do. In my repo I have three branches. master > branch_1 > branch_2 From branch_1 git status and all is clear no files are staged or modified. From branch_2 git checkout branch_2 and type git status again and all of […]

Git Baby is a git and github fan, let's start git clone.