Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Workflow: Share code between computers without pushing to public repo

Tags:

git

workflow

I work at a company which uses Git for our version control. We're using a hosted repo service (Beanstalk) as our internal "public" (by that I mean accessible to the whole dev team) repo. I have two computers that I normally work on for writing code. I like using some of the history rewriting features of Git, specifically rebasing and amending commits, but I really don't like using them after I've pushed something to a published branch. Yet, I need to be able to share code between these two computers, and preferably no one else.

What I'd like is an easy way to share my code between the two computers, without having to share it with everyone else. I have considered Airdrop (both computers are Macs), and ssh. What would be the suggested way of achieving this, while taking advantage of git's distributed nature?

like image 637
s73v3r Avatar asked Jul 10 '12 18:07

s73v3r


People also ask

Can you use Git without a server?

Git will work happily without a central server, although many teams find it convenient to have a central repository. If by "server", you mean "install server software", git will also work (central repository or not) without any special software, through ssh or on the file system.

What happens if two people push to git at the same time?

If server detects a conflict when someone pushes data (and if two users are doing this "simultaneously" one of the pushes will be conflicting, because it will be applied only after the other one completes), the server will reject it, and the unlucky user shall then resolve conflicts and try to push again.

How to share a git repository with another repository?

Whether working on a team or just wanting to back up their own code, developers need to share commits with a repo on another computer. Use the git push command to take commits from the local repo and write them into a remote repo. Git is set up in cloned repos to connect to the source of the clone, also known as origin.

What is a git workflow?

Comparing Workflows A Git Workflow is a recipe or recommendation for how to use Git to accomplish work in a consistent and productive manner. Git workflows encourage users to leverage Git effectively and consistently. Git offers a lot of flexibility in how users manage changes.

How do I push changes to a local Git repo?

If working in a repo created on the local system with git init, you'll need to set up a connection to the team's Git server before changes can be pushed. Learn more about setting up remotes and pushing changes in Visual Studio or Visual Studio Code.

How to use Git push to share updates?

The first time git push is run, adding the -u option tells Git to start tracking the local branch to branchname from the origin repo. After this one-time setup of tracking information, team members can use git push directly to share updates quickly and easily. Learn more about branches in GitHub or Azure DevOps.


3 Answers

You can push, fetch and pull between the machines freely assuming you have ssh access between them:

git push computer2:projects/prog HEAD:tmp

or, if you are on computer2:

git pull computer1:projects/prog HEAD

or

git fetch computer1:prj/prog branch1:t1
git fetch computer1:prj/prog branch2:t2
git merge t1 t2

or

git fetch computer1:prj/prog branch1 branch2 branch3
git merge FETCH_HEAD

and so on... See git help fetch for more examples.

like image 117
fork0 Avatar answered Sep 24 '22 16:09

fork0


You can run an instant git server on one of the machines, either using git-daemon or something like this: https://gist.github.com/1525217

like image 22
rlc Avatar answered Sep 23 '22 16:09

rlc


I don't see why you cannot create temp working branches that are clearly indicated as such on the remote repo, but if you want an alternative and both computers are connected by network and accessible via ssh, you could possibly set up either or both of them as additional remotes and push from one to the other in any direction. It may be confusing to get it right the first time though as you do not want to push to the wrong remote.

like image 28
prusswan Avatar answered Sep 25 '22 16:09

prusswan